简体   繁体   English

运行带有“错误:无法找到或加载主类”的 jar

[英]run jar with `Error: Could not find or load main class`

I create jar file by Intellij by these steps: File -> Project Structure -> Project Settings -> Artifacts -> Click green plus sign -> Jar -> From modules with dependencies我通过 Intellij 通过以下步骤创建 jar 文件:文件 -> 项目结构 -> 项目设置 -> 工件 -> 单击绿色加号 -> Jar -> 来自具有依赖项的模块

I run it by java -jar XX.jar , but I get an error: Error: Could not find or load main class com.guangyan.upf.Main我通过java -jar XX.jar运行它,但出现错误: Error: Could not find or load main class com.guangyan.upf.Main

there is my jar file look like:我的 jar 文件如下所示: 在此处输入图片说明

How do I solve this problem?我该如何解决这个问题? Thanks in advance!提前致谢!

When creating the jar artifact make sure you have specified the directory for manifest file. 创建 jar 工件时,请确保您已指定清单文件的目录。 Then add the main class in manifest:然后在清单中添加主类:

Manifest-Version: 1.0
Main-Class: sample.Main

Or else you can follow this tutorial for how to create runnable jar artifact and run it using Gradle in IntelliJ IDEA.或者,您可以按照本教程了解如何创建可运行的 jar 工件并在 IntelliJ IDEA 中使用 Gradle运行它。

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

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