[英]How to create executable jar with maven and system dependencies?
我的 Maven 项目中几乎没有系统依赖项,我已将其包含如下:
<dependency>
<groupId>Com.myCompany</groupId>
<artifactId>myArtifact</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${project.basedir}\lib\myArtifact-1.0.jar</systemPath>
</dependency>
我正在尝试创建一个包含所有必需依赖项的可执行 jar [fat jar],因此该 jar 可以独立运行。
我正在使用“maven-assembly-plugin”以这种方式进行打包:
<plugin>
<artifactId>maven-assembly-plugin<artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true<addClasspath>
<mainClass>com.mycompany.Application</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
问题是,当创建包时,系统依赖项不包含在 jar 中,我在运行它时遇到 ClassNotFound 异常。
有人可以指导我正确的配置方式吗?
更新:
很少有人提到我可以将依赖项安装到本地存储库。 这里的问题是我们有一个自动构建服务器,每当我们提交到 repo 时就会触发它。 我真的不想将它们安装在远程构建服务器上。
深入挖掘,发现这个hacky配置(不推荐!!)
在 Maven 程序集插件中引用此 xml:
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>${basedir}/assembly.xml</descriptor>
</descriptors>
</configuration>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>jar-with-all-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
<dependencySet>
<outputDirectory>/</outputDirectory>
<unpack>true</unpack>
<scope>system</scope>
</dependencySet>
</dependencySets>
</assembly>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.