Java 从 Eclipse 导出 jar 时出现“无法从给定的启动配置中找到主要方法”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4115471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Could not find main method from given launch configuration" error when exporting jar from Eclipse
提问by Maciek Sawicki
I developed my program using Eclipse as my IDE. I used to use File|Export| Runnable JAR file
option for creating dist build for client.
我使用 Eclipse 作为我的 IDE 开发了我的程序。我曾经使用File|Export| Runnable JAR file
选项为客户端创建 dist 构建。
I was working with project using Run or (often) Debug button in eclipse (so I have configuration for project with valid main method).
我正在使用 Eclipse 中的 Run 或(通常)Debug 按钮处理项目(所以我使用有效的 main 方法配置了项目)。
Unfortunately when I created build yesterday I had following error when I tried to run app:
不幸的是,当我昨天创建构建时,当我尝试运行应用程序时出现以下错误:
Failed to load Main-Class manifest attribute from My.jar
Then when I retried exporting I found the following problem in export log:
然后当我重试导出时,我在导出日志中发现了以下问题:
Could not find main method from given launch configuration
I have no idea what could cause this problem. I think I hadn't change anything in my project configuration. And I'm test my builds so I'm sure this option used to work correctly.
我不知道是什么导致了这个问题。我想我没有改变我的项目配置中的任何内容。我正在测试我的构建,所以我确信这个选项曾经正常工作。
I will appreciate any help.
我将不胜感激任何帮助。
采纳答案by maximdim
Are you selecting correct 'Launch Configuration' in the export dialog? Make sure it's from your project.
您是否在导出对话框中选择了正确的“启动配置”?确保它来自您的项目。
Also, once exported you could unzip jar file and look into 'META-INF/MANIFEST.MF' file - there should be 'Main-Class' entry with fully qualified name of your class where the main() method is.
此外,一旦导出,您可以解压缩 jar 文件并查看“META-INF/MANIFEST.MF”文件 - 应该有“Main-Class”条目,其中包含 main() 方法所在的类的完全限定名称。
回答by Waz
I had this problem and none of the other options worked. Even removing and starting with a new workspace. In my case the problem was that I hadn't manually added the "classes" directory of my project to the classpath of the debug configuration that I was using to debug the java app. I don't know why it didn't pick up the classes directory automatically as part of the project from which I was running the app. In any case it started working again after that.
我遇到了这个问题,其他选项都不起作用。甚至删除并从新工作区开始。就我而言,问题是我没有手动将项目的“classes”目录添加到我用来调试 java 应用程序的调试配置的类路径中。我不知道为什么它没有自动选择 classes 目录作为我运行应用程序的项目的一部分。无论如何,在那之后它又开始工作了。
回答by Zeno Van Hoeserlande
just had the same problem :s it's annoying but easy to manually fix in the manifest file.
刚刚遇到了同样的问题:这很烦人,但很容易在清单文件中手动修复。
- open the .jar file with winrar or 7zip.
- locate the manifest file (META-INF folder)
- change it to this.
- 使用 winrar 或 7zip 打开 .jar 文件。
- 找到清单文件(META-INF 文件夹)
- 把它改成这个。
Manifest-Version: 1.0
main-class: (package).(main-class)
Manifest-Version: 1.0
main-class: (package).(main-class)
In my case i had it in the default package.
就我而言,我将它放在默认包中。
Manifest-Version: 1.0
main-class: run
Manifest-Version: 1.0
main-class: run
回答by kaivalya patil
If you are not able to find your class file in Launch configuration, Right click on your project - > run as Java Application. Now export again.
如果您无法在 Launch 配置中找到您的类文件,请右键单击您的项目 - > 作为 Java 应用程序运行。现在再次导出。