我正在使用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不包含我的项目文件。使用
运行jarjava -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
。]
通过堆栈溢出I found the solution:
运行mvn clean compile assembly:single
,而不是mvn clean install assembly:single
。 :-)