简体   繁体   English

我在使用Java 1.9导出可运行的JAR时遇到问题

[英]I’m having issues exporting runnable JAR using Java 1.9

I'm using Java 1.9 and Eclipse Oxygen and when I try to export Runnable JAR File it says JAR Creation error. 我正在使用Java 1.9和Eclipse Oxygen,当我尝试导出可运行的JAR文件时,它显示JAR创建错误。 When I see details it tells me that “Could not find main method from given launch configuration”. 当我看到详细信息时,它告诉我“无法从给定的启动配置中找到主要方法”。 I've already selected the class file which has main method but same problem exists. 我已经选择了具有主要方法的类文件,但是存在相同的问题。 If I try to do the same thing in Java 1.8 with Eclipse Oxygen it exports fine but with some warnings but that is ok. 如果我尝试使用Eclipse Oxygen在Java 1.8中执行相同的操作,则它可以很好地导出,但带有一些警告,但是可以。 In Java 1.8 it exports. 在Java 1.8中,它可以导出。 But in Java 1.9 with Eclipse Oxygen it does not export at all. 但是在带有Eclipse Oxygen的Java 1.9中,它根本不会导出。 Does anybody have this problem using Java 1.9 and Eclipse Oxygen? 使用Java 1.9和Eclipse Oxygen会有人遇到这个问题吗? Please let me know the solution. 请让我知道解决方案。 Thanks in advance. 提前致谢。

I have faced that issue before. 我以前遇到过这个问题。

Solution 1: 解决方案1:

right click in the class that have the main method 右键单击具有main方法的类

go to Run As and select Run Configurations... 转到Run As并选择Run Configurations...

make sure that property Main class is the right package path to the class that have main method 确保属性Main class是具有main方法的类的正确包路径

if the main method was in another class, delete its run config from the list at the left, So the app don't get confused. 如果main方法在另一个类中,请从左侧列表中删除其run config ,因此应用程序不会感到困惑。

在此处输入图片说明


Solution 2: 解决方案2:

If the first one not working with you, So you can do the following: 如果第一个不与您合作,那么您可以执行以下操作:

after exporting the Jar file with error you mentioned 导出带有错误的Jar文件后,您提到了

go to jar file and open it with extract tool ex. 转到jar文件,然后使用解压缩工具ex打开它。 Winrar

enter to META-INF directory and view or edit the file MAINFEST.MF inside 进入META-INF目录并查看或编辑其中的MAINFEST.MF文件

add this line to the file with the right path: 将此行添加到具有正确路径的文件中:

Rsrc-Main-Class: right.path.to.class.ClassName

Save and try to run again.. 保存并尝试再次运行。


Update according to comments 根据评论更新

I have recheck it again, your problem is at export the Jar file, the selected launch configuration is wrong, because the path to main method is wrong. 我再次进行了重新检查,您的问题是在导出Jar文件时,所选的启动配置错误,因为main方法的path错误。

Usually, this is happen because you change the class or class name that contain main method. 通常,发生这种情况是因为您更改了包含main方法的class或类名。

the best way to solve it is 解决它的最好方法是

1- remove all Java Application run config, that appear in the previous Pic. 1-删除上一张Pic中出现的所有Java Application运行配置。

2- re-run the app by clicking right mouse click on the project and select Run As and then select Java Application 2-通过右键单击项目并选择Run As ,然后选择Java Application重新运行该应用Java Application

3- After the app run successfully, try now to export the app you will find only one Lunch Configuration and it will be the right one. 3-应用程序成功运行后,立即尝试导出该应用程序,您将仅找到一种Lunch Configuration并且它是正确的。

also: 也:

“Could not find main method from given launch configuration” “无法从给定的启动配置中找到主要方法”

IF that is the export problem, a JAR file will appear but with no Main method path, So you can't run it. 如果这是导出问题,将显示一个JAR文件,但没有Main方法路径,因此您无法运行它。

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

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