如何在运行当前项目之前在maven中运行依赖jar

时间:2017-01-12 10:50:45

标签: java maven build build-dependencies

我有一个maven项目,我试图从远程存储库中获取一个jar并将其添加到我的本地存储库。在添加而不是引用其类之后,我需要运行该jar作为当前项目的输入。

我尝试过,并且没有构建问题,但仍然没有触发运行依赖项。

我的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>secmaven</groupId>
    <artifactId>secmaven</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>secmaven</name>
    <description>secmaven</description>

<build>
<pluginManagement>
<plugins>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.3</version>
    <executions>
      <execution>
        <goals>
          <goal>properties</goal>
        </goals>
      </execution>
    </executions>
</plugin>

<plugin>
   <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2</version> 

    <executions>
        <execution>
            <id>exec-one</id>
            <phase>verify</phase>
            <configuration>
                <includeProjectDependencies>false</includeProjectDependencies>
                <includePluginDependencies>true</includePluginDependencies>
                <executableDependency>
                    <groupId>parent</groupId>
                    <artifactId>parent</artifactId>
                </executableDependency>

                <!-- Look up the main class from the manifest inside your dependency's JAR -->
                <mainClass>mainclass</mainClass>
                <arguments>
                </arguments>
            </configuration>
            <goals>
              <goal>java</goal>
           </goals>
        </execution>
    </executions>
        <dependencies>
        <dependency>
            <groupId>parent</groupId>
            <artifactId>parent</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>C:\....\parent.jar</systemPath>
        </dependency>
        </dependencies>
</plugin>    
</plugins>
</pluginManagement>
</build>
</project>

1 个答案:

答案 0 :(得分:1)

您可以使用maven聚合器项目pom。

示例:

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.codehaus.mojo</groupId>
  <artifactId>my-parent</artifactId>
  <version>2.0</version>
  <packaging>pom</packaging>

  <modules>
    <module>proj1</module>
    <module>proj2</module>
  </modules>
</project>

这样proj1将始终在proj2之前运行。

我认为这就是你想要的。

有关详细信息,请参阅https://maven.apache.org/pom.html#Aggregation