如何在另一个war文件中添加jar以获取Maven依赖关系?

时间:2019-05-29 14:00:40

标签: maven ant

我有一个传统的ant项目,该项目需要进行第三方战争,将其解压缩,然后将其中的资源和库(超过100个jar)用于Build。

在Maven中,我能够从存储库中获取此war文件并将其解压缩。但是,如何将jar文件包含在未打包的目录中进行编译?

此外,我如何确保在解压缩后进行编译?

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="\[http://maven.apache.org/POM/4.0.0\](http://maven.apache.org/POM/4.0.0)" xmlns:xsi="\[http://www.w3.org/2001/XMLSchema-instance\](http://www.w3.org/2001/XMLSchema-instance)" xsi:schemaLocation="\[http://maven.apache.org/POM/4.0.0\](http://maven.apache.org/POM/4.0.0) \[http://maven.apache.org/xsd/maven-4.0.0.xsd\](http://maven.apache.org/xsd/maven-4.0.0.xsd)">
<modelVersion>4.0.0</modelVersion>
<groupId>project1</groupId>
<artifactId>project1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>project1 Maven Webapp</name>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.10</version>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>com.abc.third-party</groupId>
                                <artifactId>externalWar</artifactId>
                                <version>1.0.0</version>
                                <type>war</type>
                                <overWrite>false</overWrite>
                                <outputDirectory>target</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
</project>

1 个答案:

答案 0 :(得分:1)

第一步,尝试将依赖插件绑定到在编译之前运行的生命周期阶段,例如:generate-sources。因此,请确保在compile阶段运行时,存在未打包的源。