Java 应用程序中的奇怪行为(由 Eclipse 启动时运行,但使用 java -jar 时出现错误)
我有一个 Java 应用程序,当使用相同的 JAR 运行时(我已经全部刷新了它们),运行 在 Eclipse 上没问题,但是当使用命令行参数运行时:
java -jar name.jar
以及 $JRE/lib/ext/ 上的所有依赖项都会
在 Class.createInstance() 行上出现错误。
每个依赖的 .jar 都是使用 Eclipse 生成的(右键单击包上方 > 导出 > JAR)。
编辑:
我在 Eclipse 中有 2 个项目。第一个是我运行的(我们称之为主 jar),另一个有一些在这个项目中使用的实用程序(tet 我们称之为实用程序)。
错误是ClassNotFound。当寻找主 jar 上的类时,它会发生在 utils jar 上。
try {
Class.forName(proxyFieldType.getName());
} catch (ClassNotFoundException e) {
...
}
当 JRE/lib/ext 上没有库时,Eclipse 可以正常运行,但是当我将从 utils 项目上的代码生成的 utils.jar(通过右键单击 package > Export > JAR 生成)放在 JRE/lib 上时/ext,给出了该错误。
I have a Java app that, when runned with the same JARs (I've refreshed them all), runs
OK on Eclipse but, when running with the command line args:
java -jar name.jar
with all of the dependencies on $JRE/lib/ext/
gives an error on a Class.createInstance() line.
Every dependant .jar are generated using Eclipse (right click above package > Export > JAR).
EDIT:
I have 2 projects in eclipse. The first it's the one I run (let's call it main jar) and the other have some utils used in this project (tet's call it utils).
The error is ClassNotFound. It happens on utils jar, when looking for a a class that's on main jar.
try {
Class.forName(proxyFieldType.getName());
} catch (ClassNotFoundException e) {
...
}
When there's no libs on JRE/lib/ext runs ok with Eclipse, but when I put utils.jar, generated from the code on my utils project (generated with right click over package > Export > JAR), on JRE/lib/ext, gives that error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 -classpath 参数提供所有依赖项 jar。
supply all the dependency jars using -classpath argument.