简体   繁体   English

如何使用 maven 和系统依赖项创建可执行的 jar?

[英]How to create executable jar with maven and system dependencies?

I have few system dependencies in my maven project which I have included like this:我的 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>

I am trying to create a executable jar [fat jar] which includes all the required dependencies , so the jar can run standalone .我正在尝试创建一个包含所有必需依赖项的可执行 jar [fat jar],因此该 jar 可以独立运行。

I am using "maven-assembly-plugin" for packaging in this way:我正在使用“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>

The problem is that when the package is created the system dependencies are not included in the jar and I encounter ClassNotFound exceptions while I run it.问题是,当创建包时,系统依赖项不包含在 jar 中,我在运行它时遇到 ClassNotFound 异常。

Can someone guide me with the correct way of configurations?有人可以指导我正确的配置方式吗?

Update:更新:

As few people mentioned I could install of the dependencies to local repository .很少有人提到我可以将依赖项安装到本地存储库。 The problem here is that We have a automated build server which gets triggered when ever we commit to the repo.这里的问题是我们有一个自动构建服务器,每当我们提交到 repo 时就会触发它。 I really don't want to install them on the remote build server.我真的不想将它们安装在远程构建服务器上。

Digging deep , found this hacky configuration (NOT recommended!!)深入挖掘,发现这个hacky配置(不推荐!!)

Reference this xml in the maven assembly plugin:在 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.

相关问题 如何使用 Maven 创建具有依赖关系的可执行 JAR? - How can I create an executable JAR with dependencies using Maven? 如何使用Maven创建一个没有依赖关系的可执行jar? - How can I create an executable jar without dependencies using Maven? Maven 可执行文件 JAR 与依赖项 - Maven Executable JAR with dependencies Maven插件创建可执行jar,依赖项未解包(带jar的jar) - Maven plugin to create executable jar with dependencies not unpacked (jar with jars) 如何使用Maven在jar的子文件夹中创建具有依赖项的可执行jar? - How can I create an executable jar with dependencies in sub folder in jar using Maven? 如何创建包含所有 Maven 依赖项的不可执行 JAR 文件 - How to create a non-executable JAR file that includes all Maven dependencies 如何使用 Maven 创建具有依赖项的不可执行 JAR? - How can I create a non-executable JAR with dependencies using Maven? 如何使用具有外部依赖项的maven创建和运行可执行jar? - How do I create and run an executable jar with maven that has external dependencies? 如何使用Maven阴影插件仅创建一个具有所有依赖项的可执行jar,而不是两个 - How to create only one executable jar with all dependencies inside it using maven shaded plugin instead of two 如何使用maven生成包含依赖项子集的可执行jar? - How to produce a executable jar with maven that contains a subset of dependencies?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM