gpt4 book ai didi

java - 创建 Jar 存档给出 "Could not find or load main class"

转载 作者:行者123 更新时间:2023-12-01 06:11:34 27 4
gpt4 key购买 nike

$ cat Manifest.txt 
Main-Class: org.fenix.llanfair.Llanfair

$ cat org/fenix/llanfair/Llanfair.java | grep main
public static void main(String[] args) {
$ jar cfm Llanfair.jar Manifest.txt org
$ java -jar Llanfair.jar
Error: Could not find or load main class org.fenix.llanfair.Llanfair
$ jar -xf Llanfair.jar
$ cat Llanfair/META-INF/MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.8.0_25 (Oracle Corporation)
Main-Class: org.fenix.llanfair.Llanfair

$ ls Llanfair/org/fenix/llanfair/ | grep Llanfair
Llanfair$1.class
Llanfair$2.class
Llanfair$MenuItem.class
Llanfair$RecentMenuItem.class
Llanfair.class
$ java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

我希望 java -jar Llanfair.jar 启动我的应用程序,所以我不确定我在这里做错了什么。当我正常运行 java 代码时,lib/中确实有几个文件位于我的类路径中,我需要包含这些文件吗?

如果重要的话,我的操作系统是 Mac OS 10.11.1。

最佳答案

Llanfair.jar 中的文件结构似乎错误。

根据您的评论jar -xf Llanfair.jar创建一个类似的结构

Llanfair/META-INF/MANIFEST.MF 
Llanfair/org/fenix/llanfair/Llanfair.class

但是jar文件内部的结构必须是

META-INF/MANIFEST.MF 
org/fenix/llanfair/Llanfair.class

关于java - 创建 Jar 存档给出 "Could not find or load main class",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33689262/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com