[英]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: 我这样导出项目:
The libraries are added like this: 库的添加如下:
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.