【问题标题】:NoSuchMethodError when running jar运行 jar 时出现 NoSuchMethodError
【发布时间】:2017-01-04 02:09:38
【问题描述】:

我用 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)

我的所有依赖项都包含在 jar 文件中(我已使用 WinRar 检查过)...

此方法出现错误:

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();
}

在这一行:

building = new Building(Integer.parseInt(args[0]), args[1], 0, 0, 0);

我用这个命令运行它:

java -jar rms.jar 1 data/home#

【问题讨论】:

  • 您确定args[0]args[1] 在运行时可用吗?
  • 你是如何从控制台运行应用程序的?

标签: java exception jar nosuchmethoderror


【解决方案1】:

我还没有发现问题,但是我已经解决了:)

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-21
    • 2021-11-19
    • 2014-07-21
    • 2010-12-01
    相关资源
    最近更新 更多