简体   繁体   English

带有编译过的ubuntu jar的Windows 7中出现“找不到或加载主类”错误

[英]“could not find or load main class” error in windows 7 with compiled ubuntu jar

I have a simple Swing app compiled with netbeans 7.1.2 on a ubuntu machine which has the java version: 我在具有Java版本的ubuntu机器上使用netbeans 7.1.2编译了一个简单的Swing应用程序:

java version "1.6.0_22" OpenJDK Runtime Environment (IcedTea6 1.10.4) (6b22-1.10.4-0ubuntu1~11.04.1) OpenJDK Server VM (build 20.0-b11, mixed mode) Java版本“ 1.6.0_22” OpenJDK运行时环境(IcedTea6 1.10.4)(6b22-1.10.4-0ubuntu1〜11.04.1)OpenJDK服务器VM(内部版本20.0-b11,混合模式)

jar works great when i use the shell using "java -jar filename.jar" in linux but in the windows 7 with the java version 1.7.05 i get: "Error: could not find or load main class" 当我在Linux中使用“ java -jar filename.jar”使用外壳程序,但在Java版本为1.7.05的Windows 7中使用jar时,我得到:“错误:找不到或加载主类”

How do i resolve this issue? 我该如何解决这个问题?

This error usually shows up when you don't include the current directory ( . ) in the classpath. 当您在类路径中不包含当前目录( . )时,通常会显示此错误。

If there are any external libraries that you specify when starting the program, then you probably do something like java -jar -classpath dir/library.jar program.jar . 如果在启动程序时指定了任何外部库,则可能会执行类似java -jar -classpath dir/library.jar program.jar Instead, add . 而是添加. to the classpath: java -jar -classpath .;dir/library.jar program.jar 到类路径: java -jar -classpath .;dir/library.jar program.jar

Other possibilities are: 其他可能性是:

  • you didn't include a Manifest in the JAR 您没有在JAR中包含清单
  • in the Manifest that you did include, you didn't specify which is the main class, or you did it wrong. 在您包含的清单中,您没有指定哪个是主类,否则您做错了。

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

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