java – 使用Maven在单独的jar中构建和打包应用程序和依赖项
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 使用Maven在单独的jar中构建和打包应用程序和依赖项,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2607字,纯文字阅读大概需要4分钟。
内容图文
![java – 使用Maven在单独的jar中构建和打包应用程序和依赖项](/upload/InfoBanner/zyjiaocheng/787/823ec720dd804a3a9bb871be8073b3e8.jpg)
我正在寻找一个pom.xml配置,它将我的应用程序打包在一个jar中,所有应用程序依赖项打包在另一个jar中.我查看了maven-assembly-plugin并使用以下配置,我能够构建一个应用程序jar,然后是一个包含所有依赖项的应用程序jar,但我需要依赖jar而不包含我的应用程序:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${project.artifactId}-${project.version}</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
</executions>
</plugin>
谢谢
解决方法:
我已经看到通过在模块中构建应用程序解决了这个问题这是一个很好的博客:http://giallone.blogspot.com/2012/12/maven-install-missing-offline.html?_sm_au_=iVVnK0HqJZDtb1Hw
对于您的情况,您可以使用一个名为“dependencies”的模块,该模块使用maven-dependency-plugin和maven-assembly-plugin来复制所有依赖项并将它们打包在一个jar中.然后您的应用程序可以引用该jar作为它在单独模块中的依赖性.顶级将构建两者.
顶级pom
.
.
.
<packaging>pom</packaging>
.
.
<modules>
<module>dependencies</module>
<module>yourApp</module>
</modules>
.
.
.
依赖性pom
.
.
.
<dependencies>
<dependency>
<groupId>some.group.id</groupId>
<artifactId>yourFirstDependency</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>some.group.id2</groupId>
<artifactId>yourSecondDependency</artifactId>
<version>1.1.4</version>
</dependency>
<dependencies>
<build>
<defaultGoal>install</defaultGoal>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
.
.
.
主要应用pom
.
.
.
<!-- Reference your dependency module here as the first in the list -->
<dependencies>
<dependency>
<groupId>your.group.id</groupId>
<artifactId>yourDependencyJarName</artifactId>
<version>1.0</version>
</dependency>
.
.
</dependencies>
.
.
.
内容总结
以上是互联网集市为您收集整理的java – 使用Maven在单独的jar中构建和打包应用程序和依赖项全部内容,希望文章能够帮你解决java – 使用Maven在单独的jar中构建和打包应用程序和依赖项所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。