java - 无法构建jar项目
问题描述
我需要有关构建 jar 文件的帮助。我总是收到消息错误:尝试执行 jar 文件时无法找到或加载主类 Main。
我的 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
}
在构建看不到 Main 类的 jar 文件时,我真的不知道自己做错了什么。
解决方案
在我添加 env 变量后,它开始看到 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)
推荐阅读
- ios - 我应该使用 UserDefaults 还是 Core Data?
- python - 通过 CLI 调用 lambda 函数时出错
- google-apps-script - 如果日期不是 Google Apps 脚本中的今天日期,如何停止程序执行
- latex - 如何使用 biblatex 删除书目列表中的标签?
- javascript - window.matchMedia 在 Safari 中不起作用
- sql-server - 在两个日期时间之间分组
- python - Tradingview pinescript - 需要在前 2 天的高点和低点绘制水平虚线
- scala - Spark Json - 使用 nullable=false 应用架构
- pyspark - Pyspark - 固定列的汇总
- c# - 通过保存到 .txt 文件来持久化自定义类时的权限问题