[英]NoSuchMethodError when running jar
I've made a small application in Java, which runs fine in Intellij Idea, however once I try to export it to a jar file and try to run it, it gives me this error: 我用Java开发了一个小型应用程序,该应用程序在Intellij Idea中可以正常运行,但是一旦我尝试将其导出到jar文件并尝试运行它,它就会给我这个错误:
Exception in thread "main" java.lang.NoSuchMethodError: nu.apiary.PF2.Building.<init>(ILjava/lang/String;III)V
at nu.apiary.RMS.Main.main(Main.java:13)
All of my dependencies are included in the jar file (I've checked with WinRar)... 我所有的依赖项都包含在jar文件中(我已经与WinRar进行过检查)...
The error occurs in this method: 在此方法中发生错误:
public static void main(String[] args) {
try {
building = new Building(Integer.parseInt(args[0]), args[1], 0, 0, 0);
} catch (Exception e) {
System.err.println("Incorrect building name entered!");
System.err.println("Closing now!");
System.exit(-1);
}
if(args.length == 2)
server = new Server(8998);
else if(args.length == 3)
server = new Server(Integer.parseInt(args[2]));
else if(args.length < 2 || args.length > 3) {
System.err.println("Incorrect amount of arguments, correct usage:");
System.err.println("rms-[version] <height> <name> [port]");
System.err.println("Closing now!");
System.exit(-1);
}
serverThread = new Thread(server);
serverThread.start();
}
At this line: 在这一行:
building = new Building(Integer.parseInt(args[0]), args[1], 0, 0, 0);
I run it with this command: 我使用以下命令运行它:
java -jar rms.jar 1 data/home#
I have not found the problem, however I have solved it :) 我没有发现问题,但是我已经解决了:)
1. In Intellij I exported the project to Eclipse. (File --> Export to Eclipse)
2. I then opened the project in eclipse.
3. I created a new run configuration.
4. I then exported the project as a runnable jar file. (File --> Export... --> Java --> Runnable Jar --> Complete the export dialog)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.