简体   繁体   English

使用Eclipse导出带有外部库的Java Project

[英]Export Java Project with external libraries using Eclipse

i'm trying to export my Java Project into a runnable JAR file with eclipse but if i want to run the finished JAR file I always get the error 我正在尝试将Java项目导出到带有Eclipse的可运行JAR文件中,但是如果我想运行完成的JAR文件,我总是会收到错误消息

Java Virtual Machine Launcher

Could not find the main class: src.main. Program will exit.

src.main is my main class, if i open the jar with winrar this class is in the folder src in the jar file. src.main是我的主类,如果我使用winrar打开jar,则该类位于jar文件中的src文件夹中。

I export the Project like this: 我这样导出项目:

  • Right click on the Project name 右键单击项目名称
  • Export 出口
  • Runnable JAR file -> Next 可运行的JAR文件->下一步
  • Launchconfig: my main class. Launchconfig:我的主班。
  • destination: ...\\Desktop\\asdf.jar 目的地:... \\ Desktop \\ asdf.jar
  • Library handling: Extract required libraries into generated JAR (I also tried all the others) 库处理:将所需的库提取到生成的JAR中(我也尝试了所有其他库)
  • Finish
  • I get a Warning: "JAR export finished with warnings. .." 我收到警告:“ JAR导出已完成警告。
  • OK

The libraries are added like this: 库的添加如下:

  • Right click on the Project name 右键单击项目名称
  • Properties 性质
  • Java Build Path Java构建路径
  • Libraries 图书馆
  • Add External JARs 添加外部JAR
  • And than all the libraries are together in one external folder. 而且,所有库都放在一个外部文件夹中。

What am I doing wrong? 我究竟做错了什么?

Does src.Start have a proper "public static void main(String[] args)" method? src.Start是否具有正确的“ public static void main(String [] args)”方法?

Are you trying to start the app like this: 您是否要像这样启动应用程序:

"java -jar myjar.jar" or "java -cp myjar.jar src.start" “ java -jar myjar.jar”或“ java -cp myjar.jar src.start”

Also, are you building the manifest by hand, or letting eclipse do it? 另外,您是手动构建清单还是让月食完成? I don't remember ever seeing eclipse add a classpath entry in the manifest but I might have missed it. 我不记得曾经看到eclipse在清单中添加类路径条目,但是我可能会错过它。

On the "Jar Manifest Specification" panel during the export, just select "generate the manifest file" and fill in the "Main class:" entry in the input field. 在导出期间,在“ Jar Manifest规范”面板上,只需选择“生成清单文件”,然后在输入字段中填写“ Main class:”条目。

The first thing that I recommend you: don't use src.main in the way that you are doing it right now. 我向您推荐的第一件事:不要以您现在正在使用的方式使用src.main。 In Java usually we use a folder called src or src/main or src/main/java to put the sources. 在Java中,通常使用名为src或src / main或src / main / java的文件夹放置源。 Then, to use this as a package and class name is not a good idea. 然后,将其用作包和类名不是一个好主意。 Secondly; 其次; don't call your class main it is not a keyword in Java, you can create a class with this name but... it's not a good idea. 不要将您的类称为main,这不是Java中的关键字,您可以使用该名称创建一个类,但是...这不是一个好主意。

And the solution to your problem: you need to set up your Main-Class and your Class-Path in your manifest file and be sure about the structure of your package (your jar), take a look into this tutorial , it will help you. 问题的解决方案:您需要在清单文件中设置Main-Class和Class-Path,并确定包(您的jar)的结构,请看一下本教程 ,它将为您提供帮助。

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

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