简体   繁体   English

Java应用程序中的异常行为(由Eclipse启动时运行,但java -jar给出错误)

[英]Strange behaviour in Java app (runs when lauched by Eclipse but gives error with java -jar)

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运行时(我都刷新了它们),可以在Eclipse上运行OK,但是当使用命令行args运行时:

java -jar name.jar java -jar name.jar

with all of the dependencies on $JRE/lib/ext/ 与所有依赖$ JRE / lib / ext /

gives an error on a Class.createInstance() line. 在Class.createInstance()行上给出错误。

Every dependant .jar are generated using Eclipse (right click above package > Export > JAR). 每个相关的.jar都是使用Eclipse生成的(右键单击包上方的> Export> JAR)。

EDIT: 编辑:

I have 2 projects in eclipse. 我有2个日食项目。 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). 第一个是我运行的(我们称它为主jar),另一个是该项目中使用的一些utils(tet称为utils)。

The error is ClassNotFound. 错误是ClassNotFound。 It happens on utils jar, when looking for aa class that's on main jar. 寻找主jar上的类时,它会在utils 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. 当JRE / lib / ext上没有库时,可以在Eclipse上正常运行,但是当我将utils.jar(由我的utils项目中的代码生成(通过右键单击包> Export> JAR生成))放在JRE / lib / ext上时,给出该错误。

supply all the dependency jars using -classpath argument. 使用-classpath参数提供所有依赖项jar。

java -classpath "path of lib/ext" -jar name.jar java -classpath“ lib / ext的路径” -jar name.jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM