gpt4 book ai didi

java - 无法构建jar项目

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

我需要构建 jar 文件的帮助。尝试执行 jar 文件时,我总是收到消息 Error: Could not find or load main class Main。

This is my project Structure

我的 MANIFEST.MF 在这里:

Manifest-Version: 1.0
Main-Class: Main

还有我的 Main.java 文件:

public class Main {    
public static final Charset ISO_8859_1 = StandardCharsets.ISO_8859_1;
public static final Charset UTF_8 = StandardCharsets.UTF_8;
public static void main(String[] args) throws IOException, InvalidFormatException {
for (String arg : args) {
System.out.println("Arg " + arg);
}
//Other code removed
}

我真的不知道在构建 jar 文件时我做错了什么,它看不到主类。

最佳答案

添加环境变量后,它开始看到 main,但现在我又遇到了崩溃:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/poi/openxml4j/exceptions/InvalidFormatException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException:
org.apache.poi.openxml4j.exceptions.InvalidFormatException
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

看起来 java 在我的 jar 文件中看不到库文件。如果我使用 7zip 检查 jar 文件,我可以看到其中的库文件。 enter image description here

关于java - 无法构建jar项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59574113/

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