Reputation: 8815
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)
Upvotes: 2
Views: 1961
Reputation: 718698
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.
Upvotes: 2
Reputation: 51915
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.
Upvotes: 1