将本地JAR依赖项捆绑在目标JAR中

时间:2019-03-10 16:47:50

标签: java maven jar

我的项目结构是这样的。

ProjectX-取决于ProjectY,它是一个本地JAR,添加为依赖项,如下所示:

<dependency>
        <groupId>com.wow.projecty</groupId>
        <artifactId>projecty</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>/Users/somepath/ProjectY.jar</systemPath>
</dependency>

现在,我正在为ProjectX创建一个JAR,并使用此捆绑在JAR中的所有依赖项。

<plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>ProjectXDriver</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

这是捆绑来自Maven的所有依赖关系,而不是捆绑来自本地文件系统的所有依赖关系。在这种情况下,最终的JAR中缺少ProjectY中的类。 (也可以使用jar tf进行检查)

我想念什么?

1 个答案:

答案 0 :(得分:1)

为此我找到了快速修复。只需在本地Maven存储库中安装JAR并正常使用即可(无需system范围/ systemPath

mvn install:install-file -Dfile=ProjectY.jar -DpomFile=../pom.xml
相关问题