dje*_*lin 17 java deployment maven
我可以jar
在我的pom.xml
运行中使用以下内容部署一个mvn deploy
:
<distributionManagement>
<repository>
<id>releases</id>
<url>http://${host}:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Internal Snapshots</name>
<url>http://${host}:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
Run Code Online (Sandbox Code Playgroud)
我可以jar-with-dependencies
使用以下代码构建可执行文件:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>create-executable-jar</id>
<phase>deploy</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>my.company.app.Main</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
问题是我不知道如何将这些拼接在一起以将可执行文件部署jar
到我的Maven仓库.我真的不知道这是通过新插件还是通过向现有程序集插件添加目标或其他步骤来实现的.
如果将程序集绑定到打包阶段,则在执行构建时,它将在您的存储库中安装"常规"jar和with-dependencies jar:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>my.company.app.Main</mainClass>
</manifest>
</archive>
<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>
Run Code Online (Sandbox Code Playgroud)
然后只需运行mvn clean install deploy
将两个罐子上传到您的仓库
为了构建(所谓的)ÜberJAR并使用maven进行部署,您还可以使用shade插件。以下代码取自他们的网站,但我使用此功能进行了一个或两个项目。
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>jackofall</shadedClassifierName> <!-- Any name that makes sense -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
Run Code Online (Sandbox Code Playgroud)
在此配置中,除了常规JAR之外,您还可以将ÜberJAR作为一个部署。然后,您的JAR的用户可以决定基于分类器提取多合一软件包或具有依赖项的JAR。
我通常会使用shade插件来构建ÜberJAR(或以某种方式修改JAR),并使用Assembly插件来构建诸如安装包之类的东西(包含JAR以及可能的其他东西)。我不确定单个插件的预期目标是什么。
从本质上讲,我这样做的困难揭示了一个事实:我pom.xml
已经远远偏离了轨道。一切都会自行就位。我以前在做:
我认为这种做法有意义有几个原因,特别是当我的库没有从我的应用程序中很好地分解时。
然而,通过删除 1 和 2,所需要的只是该distributionManagement
部分,并且部署阶段会自动工作。总而言之,这是一个通过删除大量代码来真正添加功能的惊人案例。
归档时间: |
|
查看次数: |
16432 次 |
最近记录: |