views:

68

answers:

2

Hi,

I have an executable jar Client.jar that requires jndi.properties file. Since the jndi properties is not part of the Client.jar, and java -jar ignores the -classpath argument,

How can I execute the jar and let it know where the jndi.properties is?

Thanks

// Edit, error message

java -jar Client2.jar 
Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.don.Client.main(Client.java:10)
+1  A: 

You should be able to manually refer to the main class and include all the JARs on the classpath, instead of using the -jar flag.

Kaleb Brasee
+1  A: 

We need more information on how the application is told the location of the JNDI properties file.

Is it expecting the properties file location as a command line argument? If so, you should invoke the command as follows:

java -jar <jarfile> <arguments>

where the <arguments> include the relevant option giving the JNDI properties file.

Is it expecting the JNDI properties file as a system property? If so, you should invoke the command as follows:

java -jar <jarfile> -D<someproperty>=<location>

where the <someproperty> is the name of the relevant property.

Is it expecting to find property file on the classpath? If so, you should invoke the command something along the following lines:

java -cp <jarfile>:<directory> <main-class>

where <main-class> is the main class name from the JAR file manifest, and <directory> contains the JNDI properties file with the name expected by the application.

If the application is properly documented, the preferred way of setting up the JNDI properties file will be in the installation and/or usage documentation.

Stephen C
It is expecting the jndi.properties file on the classpath. I added the error that I got in the description above.
portoalet
@portoalet - the error you included does NOT say that the jndi.properties *have to be* on the classpath!
Stephen C
I ended up doing: java -Djava.naming.provider.url=jnp://localhost:1099 -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory com.don.ClientFor some reasons jndi.properties just cannot be loaded.
portoalet