开发者

Unable to run JAR file on another PC. Possible issue with Environment Variables?

I've built a JAR file and it executes fine on my PC (XP) which has Eclipse installed. It also works on another PC, which also has Eclipse.

I've tried running it on another PC(XP) that does not ha开发者_如何学Gove Eclipse. Though it contains the JDK and multiple JRE. The JAR file just does not execute by clicking or from the command prompt.

I am not entirely sure, but my best guess is the Environment Variables are not set properly. Here is the error I receive from the command prompt:

Exception in thread "main" java.lang.NoClassDefFoundError: ...

Any help would be appreciated.


It must be a CLASSPATH issue.

The stacktrace should also say which class it failed to find. Once you have that, then find which jar has that class. Then add that jar file to your classpath or add it to the classpath env variable.


This is likely a classpath issue as others have said.

One thing to note is how your jar is constructed. You have a number of options in the dialog for exporting a runnable jar;

  • Extract classes into jar
  • Zip dependencies into the jar - creates jar-in-jar-loader.jar inside the jar.
  • Place jars in a subdirectory next to the jar.

Depending on what you have chosen for this depends on how the jar will behave. If the classes are extracted, dependent classes not in the JDK should be on the classpath. I'd recommend this course of action as it is simpler.

Now, the question is - are you using a dependency on your classpath not in the build dependencies of the eclipse project? If so, it won't be packed with / zipped into / put next to the jar because eclipse doesn't know about it (but java will still find it on your system because it's on the classpath). Also, if you've saved an ANT script and updated the build path in eclipse, eclipse won't update that ANT script - that is generated once only.


Environment variables are not considered when invoking a jar file when clicking on it (equivalent to running javaw -jar your.jar).

I'm pretty sure that it doesn't work on your first PC outside of Eclipse either.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜