【发布时间】:2020-03-25 06:24:22
【问题描述】:
我正在使用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 文件确实包含依赖项,但它确实 不 包含我的项目文件。使用
运行 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。)
【问题讨论】:
-
删除配置
<sourceDirectory>..</sourceDirectory>并保持约定优于配置。此外,将插件绑定到此处记录的包阶段:maven.apache.org/plugins/maven-assembly-plugin/… 最后您可以使用mvn clean package...
标签: java maven maven-assembly-plugin