简体   繁体   English

从 IntelliJ 创建可运行的 Jar,尝试在 cmd 中运行会给出“错误:无法找到或加载主类 com.....”

[英]Creating runable Jar from IntelliJ, trying to run in cmd gives 'Error: Could not find or load main class com.....'

I'm using IntellIj to try and create a runnable Jar out of my program.我正在使用 IntellIj 尝试从我的程序中创建一个可运行的 Jar。 I've gotten a runnable jar to execute in cmd correctly for a simple hello world program, but when I try doing the same exact steps for the larger project I get the Error:我已经得到了一个可运行的 jar,可以在 cmd 中为一个简单的 hello world 程序正确执行,但是当我尝试为更大的项目执行相同的确切步骤时,我得到了错误:

Error: Could not find or load main class com.abc.project.directory.SomeClass错误:无法找到或加载主类 com.abc.project.directory.SomeClass

I've checked my MANIFEST.MF:我检查了我的 MANIFEST.MF:

Manifest-Version: 1.0
Main-Class: com.abc.project.directory.SomeClass

Which has that exactly.这正是。 The main class I selected to build the artifact off of is also 'com.abc.project.directory.SomeClass' exactly.我选择用来构建工件的主要类也是“com.abc.project.directory.SomeClass”。 I've tried just about everything like moving the META-INF folder to the same exact directy where SomeClass.java is, using different directories, using default directories, etc. to no avail.我已经尝试了几乎所有的事情,比如将 META-INF 文件夹移动到 SomeClass.java 所在的同一目录、使用不同的目录、使用默认目录等,但都无济于事。

Not too sure where I am going wrong, any help would be great!不太确定我哪里出错了,任何帮助都会很棒!

My project basically mirrors this functioning Hello World test below:我的项目基本上反映了下面这个功能正常的 Hello World 测试: 在此处输入图片说明

click file>export and select your option to create the final executable单击文件>导出并选择您的选项来创建最终的可执行文件

the problem happens because you have created a class which is in another directory than the others.Intellij can compile the file correctly if you follow the steps出现问题是因为您创建了一个类,该类位于另一个目录中而不是其他目录中。如果您按照以下步骤操作,Intellij 可以正确编译该文件

暂无
暂无

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

相关问题 Java从命令行运行jar:找不到或加载主类com.test.Main时出错 - Java run jar from command line: Error could not find or load main class com.test.Main 创建 Jar 存档给出“无法找到或加载主类” - Creating Jar archive gives "Could not find or load main class" .jar 文件错误“找不到或加载主类”与 IntelliJ - .jar file error "could not find or load main class" with IntelliJ 无法运行jar文件,出现“错误:找不到或加载主类com.trident.SchedulerMain” - Unable to run jar file getting “Error: Could not find or load main class com.trident.SchedulerMain” JavaFX 错误:当我尝试运行我的 Z6849095FCDBF43AD7Z(IntelliJ)文件时,无法找到或加载主 class home.main - JavaFX Error : Could not find or load main class home.main with gradle (IntelliJ) when I try to run my jar file 运行带有“错误:无法找到或加载主类”的 jar - run jar with `Error: Could not find or load main class` 错误:无法找到或加载主类 [Intellij] - Error: Could not find or load main class [Intellij] 错误:尝试运行JAR时无法找到或加载主类Main。 Manifest和classpath看起来很好,仍然无法正常工作? - Error: Could not find or load main class Main when trying to run JAR. Manifest and classpath look fine, still doesn't work? “错误:在尝试执行Maven生成的Jar时无法找到或加载主类com.mycompany.App” - “Error: Could not find or load main class com.mycompany.App” when trying to execute Maven-generated Jar .jar错误 - 无法找到或加载主类 - .jar error - could not find or load main class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM