Let me clarify in case my original description was not clear:
I am trying to do a simple job of looking an object up in a remote JNDI registry (192.168.1.10, i.e. not the machine itself). When run from the command line, the code above works perfectly by looking the object up in JNDI@192.168.1.10, but when run from within a JBoss server (e.g. in a servlet) running on another server, it is always looked up in the JNDI registry running on the server itself (thereby ignoring my PROVIDER_URL). I've tried looking for a jndi.properties file that may specify another URL but there are none.
I have nothing to go on at this point and have practically given up. I hope someone can help.
I have solved our problems today. We needed to change several things to make it work.
1) Start JBoss with the option "-b 0.0.0.0". Otherwise, JBoss only binds to localhost. This should usually give "connection refused" when doing remote JNDI through the server's real IP, but it didn't in our case, we just got naming errors. This might be due to network configuration and maybe because we're running under Linux VServer where localhost may have a differnt meaning than usual.
2) We accidentally were looking up in the java:-namespace. When doing this, the Context.PROVIDER_URL was silently ignored and generates no warnings or errors but does lookups locally.
I was also told that it is a good idea to set jnp.disableDiscovery = true in the InitialContext environment to ensure that you get the server you're asking for and not a different one, if the server you asked for is unavailable.
The -b flag is normally used when configuring the server from a remote client.
You can also use run.sh -b 192.168.5.78 where 192.168.5.78 is the server address (i.e. bind directly to the server's IP from the remote client).
I faced the same problem and without the -b, Jboss could not be run (this only applies to managing the server from a remote location).