使用maven-assembly-plugin时,使用maven如何在输出jar中捆绑所有依赖项和我的Java项目文件?

问题描述 投票:0回答:1

我正在使用maven-assembly-plugin从我的maven项目中创建一个输出jar。我的pom.xml的相关属性如下所示:

.
.
.
<dependencies>
    <dependency>
      .
      .
      .
    </dependency>
    .
    .
    .
</dependencies>

<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        .
        .
        .
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>my.package.TheApp</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>
        .
        .
        .
    </plugins>
</build>
.
.
.

当我运行`mvn clean install assembly:single'时,生成的jar文件确实包含依赖关系,但not不包含我的项目文件。使用

运行jar
java -jar TheApp-0.1.2-SNAPSHOT-jar-with-dependencies.jar

我收到消息Error: Could not find or load main class my.package.TheApp那么,如何包含我的项目文件?(我想到了设置useProjectArtifact,但是according to the maven-assembly-plugin doco此属性默认为true。]

java maven maven-assembly-plugin
1个回答
0
投票

通过堆栈溢出I found the solution

运行mvn clean compile assembly:single,而不是mvn clean install assembly:single。 :-)

© www.soinside.com 2019 - 2024. All rights reserved.