gpt4 book ai didi

java - 将 Maven 应用程序打包到单个 jar 中 - 但有异常(exception)

转载 作者:行者123 更新时间:2023-12-02 10:28:47 24 4
gpt4 key购买 nike

我的应用程序中有一些依赖项,我希望在构建过程中将所有依赖项打包到单个 jar 中 - 除了单个依赖项(团队的实用程序 jar)之外。发现如何使用 maven-assemble-plugin 构建单个 jar,不知道如何排除特定依赖项。

这是相关的 pom.xml 文件:

<repositories>
<repository>
<id>local-maven-repo</id>
<url>file://repository_path</url>
</repository>
</repositories>
....
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.10</source>
<target>1.10</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>app-name</finalName>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.company.appname.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>
</plugins>
</build>
...
<dependencies>
<dependency>
<groupId>com.company.utils</groupId>
<artifactId>utils</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>

最佳答案

可能Including and Excluding Artifacts会帮助你的。

更具体地说,您需要创建自己的 assemble.xml 文件:

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>jar-with-dependencies-exclude</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
<excludes>
<exclude>com.fasterxml.jackson.datatype:jackson-datatype-jsr310</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>

然后更改您的插件配置以使用此文件:

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>app-name</finalName>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.company.appname.Main</mainClass>
</manifest>
</archive>
<descriptors>
<descriptor>src/main/assembly.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>

关于java - 将 Maven 应用程序打包到单个 jar 中 - 但有异常(exception),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53727725/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com