ClassNotFoundException for main-class 运行 具有依赖项的可执行 jar

ClassNotFoundException for main-class running an executable jar with dependencies

我在这里找不到问题:

我使用 maven 插件创建了一个 jar,但是狗不会打猎。

class:

package com.foo.baitshop;

public class Design {

    public static void main(String args[]) throws IOException {

        int argLength = args.length;
    }
}

我解压缩 jar 以查看内部情况,META-INF 文件夹位于根目录中并包含清单 (MANIFEST.MF)。

看起来像这样:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: lwhite
Build-Jdk: 9.0.4
Main-Class: com.foo.baitshop.Design;

为了运行,我在保存jar的目录中执行以下命令:

java -jar baitshop2-1.0-SNAPSHOT-jar-with-dependencies.jar

在此环境中没有class外部设置的路径。

错误信息是:

fm-mltp140:target lwhite$ java -jar baitshop2-1.0-SNAPSHOT-jar-with-dependencies.jar
Error: Could not find or load main class com.foo.baitshop.Design;
Caused by: java.lang.ClassNotFoundException: com/foo/baitshop/Design;

如有任何帮助,我们将不胜感激。

我认为是分号:

Main-Class: com.foo.baitshop.Design;

需要删除的是:

Main-Class: com.foo.baitshop.Design

如果 Maven 正在生成它,则需要调试 Maven 配置以防止添加分号。可能某处的配置中有一个分号。

来自 Oracle 的关联 doc