java运行jar文件找不到主类,无法运行jar文件:找不到或加载主类Hello

I create jar file in IDEA Build>Build Artifacts. But can't run it with java -jar jarname.jar - Error: Could not find or load main class Hello. MANIFEST.MF file is in the /resources/META-INF/ folder. And here is the launcher class:

public class Hello {

public static void main(String[] args) {

System.out.println("Hello World!");

}

}

MANIFEST.MF:

Manifest-Version: 1.0

Main-Class: Hello

XLksW.jpg

EDIT: Added artifacts setting screenshot

qXwM7.jpg

解决方案

PU0fL.png

You go to project structure then choose "Artifacts" from the left tab. Add a new artifact and as you see here although I have a manifest selected and a Main class selected, on the left side it shows what it will add to the jar. On the right side it shows what's available(un-added). However, since I haven't added anything into my jar yet, it will only add the Manifest and none of the actual code.

You need to specify that you want to add the compile output to the jar or else it will only have the manifest and not your actual classes. You can do that by just double clicking on it. If you specify the directory above the compiled output, it will add the src as well I believe.

Update: Add external dependencies

HtGNw.png

c2NTb.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值