maven - 为子项创建jar并通过将第一个子类/ jar添加到第二个子类的classpath来执行目标exec:java for another child

时间:2017-12-18 09:28:50

标签: java maven

我有一个child-1 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.company.app</groupId>
    <artifactId>child-1</artifactId>
    <version>1.0</version>

    <name>child-1</name>
    <url>http://maven.apache.org</url>
    <parent>
        <groupId>com.company.app</groupId>
        <artifactId>parent</artifactId>
        <version>1.0</version>
    </parent>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>

    </dependencies>

</project>

child-2 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <name>child-2</name>
    <url>http://maven.apache.org</url>

    <artifactId>child-2</artifactId>
    <parent>
        <groupId>com.company.app</groupId>
        <artifactId>parent</artifactId>
        <version>1.0</version>
    </parent>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <mainClass>{my main class}</mainClass>
                    <cleanupDaemonThreads>false</cleanupDaemonThreads>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

parent 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.company.app</groupId>
    <artifactId>parent</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>

    <name>parent</name>
    <url>http://maven.apache.org</url>
    <modules>
        <module>child-1</module>
        <module>child-2</module>
    </modules>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>

    </dependencies>

</project>

我需要在exec:java上执行目标child-2,之后需要编译child-1中的类(可以创建为jar文件,但不应该安装),应该是添加到child-2的类路径中,以便所有编译的类都可用于child-2。有没有办法实现这个目标?

0 个答案:

没有答案