"Context.PROVIDER_URL in server jndi.properties" JBoss log / jndi.properties packaged in application diagnostics
Environment
- JBoss Enterprise Application Platform (EAP)
- 5.x
- 4.x
- JBoss Enterprise SOA Platform (SOA)
- 5.x
- 4.x
Issue
- I see the following warnings/errors on a couple of servers in our setup. I dont see the error on 1 of the servers.
WARN [org.jnp.server.NamingBeanImpl] (main) Context.PROVIDER_URL in server jndi.properties, url=localhost:1099
- I'm seeing this warning in my log file:
WARN [org.jnp.server.NamingBeanImpl] Context.PROVIDER_URL in server jndi.properties, url=<hostname>
Resolution
Remove any jndi.properties files you have packaged in your application or put in the classpath other than the one in $JBOSS_HOME/server/$PROFILE/conf/
Remove the -Djava.naming.provider.url=
Root Cause
- JBoss is picking up the wrong jndi.properties file from the classpath or is being overridden by -Djava.naming.provider.url
- The jndi.properties should not be packaged in deployments as it globally changes the jndi configuration. Deployments should setup jndi properties and pass them into new InitialContext(properties) to use a different jndi.
Diagnostic Steps
-
Using jndi-properties-byteman.zip (contains byteman script and byteman jars)
-
unzip -d $JBOSS_HOME jndi-properties-byteman.zip
-
Add this to your $JBOSS_HOME/bin/run.conf:
-
JAVA_OPTS="$JAVA_OPTS -javaagent:/$JBOSS_HOME/byteman/lib/byteman.jar=script:$JBOSS_HOME/byteman/scripts/jndi-properties.btm,boot:$JBOSS_HOME/byteman/lib/byteman.jar,boot:$JBOSS_HOME/byteman/lib/byteman-helpers.jar,listener:true,port:9091 -Dorg.jboss.byteman.transform.all=true"
-
Start JBoss EAP and reproduce the issue.
-
Using jndi-properties.btm.zip (just contains the byteman script, this assumes you already have byteman on your system)
-
Byteman can be downloaded from [1] if you do not already have it
-
Unzip jndi-properties.btm.zip and put the jndi-properties.btm in your $BYTEMAN_HOME/scripts directory
-
Create a directory $BYTEMAN_HOME/scripts and copy the jndi-properties.btm into the scripts directory.
-
Then configure your JAVA_OPTS in $JBOSS_HOME/bin/run.conf.
JAVA_OPTS="$JAVA_OPTS -javaagent:/$BYTEMAN_HOME/lib/byteman.jar=script:$BYTEMAN_HOME/scripts/jndi-properties.btm,boot:$BYTEMAN_HOME/lib/byteman.jar,listener:true,port:9091 -Dorg.jboss.byteman.transform.all=true"
- Start JBoss EAP and reproduce the issue.
Look for BYTEMAN-1, BYTEMAN-2, BYTEMAN-3, BYTEMAN-4 to see what is happening. BYTEMAN-1 & BYTEMAN-2 will show if something is setting a system property to change the JNDI URL. BYTEMAN-3 will show any time a jndi.properties is loaded. And BYTEMAN-4 will show jndi.properties files that are loaded that are not in the $JBOSS_HOME/server/$PROFILE/conf/ directory
BYTEMAN-1 / BYTEMAN-2
If you see one of these messages logged and it shows that you are setting java.naming.provider.url, then look in the stacktrace to identify the code that is calling setProperty or setProperties.
You should never set java.naming.provider.url in the java.lang.System properties. If your application needs to call the JNDI in the JVM you are running you should do:
javax.naming.Context context = new javax.naming.InitialContext();
If your application needs to call a remote JNDI, then you should do:
java.util.Hashtable env = new java.util.Hashtable();
env.put("java.naming.provider.url", "...");
...
javax.naming.Context context = new javax.naming.InitialContext(env);
If you want to keep your remote JNDI environment settings in a properties file, you can package it in your application and load it, but it MUST NOT be named jndi.properties. For example, I could create a file named my-jndi.properties and put it in the classpath of my application and load it as such:
java.util.Properties env = new java.util.Properties();
env.load(Thread.currentThread().getContextClassLoader().getResource("my-jndi.properties").openStream());
javax.naming.Context context = new javax.naming.InitialContext(env);
BYTEMAN-3 / BYTEMAN-4
If you see BYTEMAN-3 it is logging any time a jndi.properties file is being loaded.
If you see BYTEMAN-4 it is logging any time a jndi.properties file is being loaded that is not in $JBOSS_HOME/server/$PROFILE/conf/. If you see this, you should locate the jndi.properties file mentioned and remove it and use one of the alternatives described above to configure your client so that you are not globally changing the JVM settings.
[1] Content from www.jboss.org is not included.http://www.jboss.org/byteman/downloads
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.