简体   繁体   English

无法从.jar文件找到或加载主类

[英]Cannot find or load main class from .jar file

So I wrote a project in Eclipse and when I click on the green run button it works fine. 因此,我在Eclipse中编写了一个项目,当我单击绿色的运行按钮时,它运行正常。 When I export it into a jar and I double click on it a quick command prompt appears saying "cannot find or load main class...". 当我将其导出到jar中并双击它时,出现一个快速命令提示符,提示“找不到或加载主类...”。 I tried everything. 我尝试了一切。 I tried renaming registry keys, reinstalling java, changing environment variables and of course turning it on and off again. 我尝试重命名注册表项,重新安装Java,更改环境变量,当然还要再次打开和关闭它。 I read all the other threads on stack and tried everything they suggested. 我阅读了堆栈上的所有其他线程,并尝试了他们提出的所有建议。 Here is my Manifest file: 这是我的清单文件:

Manifest-Version: 1.0
Class-Path: .
Main-Class: main.Main

My Main class is in a package called main. 我的Main类位于名为main的包中。

  1. I'd like to suggest to change the package name into something other than main . 我建议将软件包名称更改为main以外的名称。
  2. don't forget to make a run configuration, which specifies the name of your main class. 不要忘记进行运行配置,该配置指定您的主类的名称。
  3. package all the related other jar files into the same package. 将所有其他相关的jar文件打包到同一软件包中。
  4. run the executable.jar as java -jar YourExecutable.Jar java -jar YourExecutable.Jar身份运行可执行文件。

And if it does not solve your problem, just see my MANIFEST.MF file in my Executable jar file. 如果它不能解决您的问题,请在我的可执行jar文件中看到我的MANIFEST.MF文件。 Maybe it can give you some clue. 也许它可以给您一些线索。

Manifest-Version: 1.0
Rsrc-Class-Path: ./ concurrentlinkedhashmap-lru-1.2.jar slf4j-api-1.7.
 5.jar org.simpleframework.jar openflowj-0.3.7-SNAPSHOT.jar mongo-java
 -driver-2.11.2.jar netty-3.9.0.Final.jar guava-15.0.jar org.restlet.e
 xt.jackson.jar logback-classic-1.0.13.jar joda-time-2.2.jar org.codeh
 aus.jackson.core.jar org.codehaus.jackson.mapper.jar openflowj-0.3.7-
 SNAPSHOT-sources.jar org.restlet.jar logback-core-1.0.13.jar org.rest
 let.ext.slf4j.jar org.restlet.ext.simple.jar openflowj-0.3.7-SNAPSHOT
 -javadoc.jar
Class-Path: .
Rsrc-Main-Class: etri.sdn.controller.Main
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader

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

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