有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

maven通过将第一个子类/jar添加到第二个子类路径,为一个子类创建jar,并为另一个子类执行goal exec:java

我有一个child-1pom,如下所示

<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-2pom如下

<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>

parentpom如下

<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>

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


共 (0) 个答案