java -jar 的类路径问题

发布于 2024-08-25 04:04:41 字数 789 浏览 3 评论 0原文

我有一个可执行 jar Client.jar 需要 jndi.properties 文件。 由于 jndi 属性不是 Client.jar 的一部分,并且 java -jar 忽略 -classpath 参数,因此

如何执行 jar 并让它知道 jndi.properties 在哪里?

谢谢

// 编辑,错误消息

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)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱你不解释 2024-09-01 04:04:41

我们需要有关如何告知应用程序 JNDI 属性文件位置的更多信息。

它是否期望属性文件位置作为命令行参数?如果是这样,您应该按如下方式调用该命令:

java -jar <jarfile> <arguments>

其中 包含提供 JNDI 属性文件的相关选项。

它是否期望 JNDI 属性文件作为系统属性?如果是这样,您应该按如下方式调用该命令:

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

其中 是相关属性的名称。

它是否期望在类路径上找到属性文件?如果是这样,您应该按照以下方式调用命令:

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

其中 是 JAR 文件清单中的主类名称, > 包含具有应用程序所需名称的 JNDI 属性文件。

如果应用程序已正确记录,设置 JNDI 属性文件的首选方法将是在安装和/或使用文档中。

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.

命比纸薄 2024-09-01 04:04:41

您应该能够手动引用主类并将所有 JAR 包含在类路径上,而不是使用 -jar 标志。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文