简体   繁体   English

从Eclipse导出jar时“无法从给定的启动配置中找到main方法”错误

[英]“Could not find main method from given launch configuration” error when exporting jar from Eclipse

I developed my program using Eclipse as my IDE. 我使用Eclipse作为我的IDE开发了我的程序。 I used to use File|Export| Runnable JAR file 我以前使用File|Export| Runnable JAR file File|Export| Runnable JAR file option for creating dist build for client. 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或(通常)调试按钮处理项目(所以我使用有效的main方法配置项目)。

Unfortunately when I created build yesterday I had following error when I tried to run app: 不幸的是,当我昨天创建构建时,当我尝试运行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. 我将不胜感激任何帮助。

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()方法所在类的完全限定名称。

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. 在我的情况下,问题是我没有手动将我的项目的“classes”目录添加到我用来调试java应用程序的调试配置的类路径中。 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. 无论如何它在那之后再次开始工作。

just had the same problem :s it's annoying but easy to manually fix in the manifest file. 只是有同样的问题:它很烦人但很容易手动修复清单文件。

  1. open the .jar file with winrar or 7zip. 用winrar或7zip打开.jar文件。
  2. locate the manifest file (META-INF folder) 找到清单文件(META-INF文件夹)
  3. change it to this. 改变它。

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

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

相关问题 Java 9 Eclipse 4.7便携式导出错误“找不到资源”,“无法从给定的启动配置中找到主要方法”。 - Java 9 Eclipse 4.7 Portable export error “resource not found”, “Could not find main method from given launch configuration.” eclipse无法从给定的启动配置中找到主要方法 - eclipse cannot find main method from given launch configuration 使用 Java+Scala+Slick2D 时“无法从给定的启动配置中找到主要方法” - "Could not find main method from given launch configuration" when using Java+Scala+Slick2D 运行Eclipse导出的jar时“找不到主类”错误 - “Could not find the main class” error when running jar exported by Eclipse 从Eclipse导出JAR - Exporting JAR from Eclipse 使用launch4j将jar从eclipse转换为exe时出错 - Error when converting jar from eclipse to exe with launch4j 错误:找不到或加载主类,但是当classpath中缺少.jar时可以工作吗? - Error: Could not find or load main class, but works when .jar is missing from classpath? 将 Spring 启动项目导出到可运行的 jar 文件时缺少 Eclipse 启动配置 - Eclipse launch configuration is missing when exporting a Spring boot project to a runnable jar file 在eclipse中运行时找不到或加载主类 - could not find or load main class when running from within eclipse 在 eclipse 中找不到主 class、jar - Could not find main class, jar in eclipse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM