maven模块执行内置jar

时间:2017-05-02 10:07:02

标签: maven execute multi-module

我有一个多模块maven项目,

我有3个模块:

  1. Source - 我正在构建的代码 - 这会输出.jar文件
  2. Java exec - 构建一个以jar文件为参数的jar,需要使用模块1中的jar运行,输出第三个jar。
  3. Bash exec - 一个bash脚本,需要以上面第三个jar的路径作为参数运行。
  4. 我该怎么做?

    我假设我需要为两个修饰符模块使用exec-maven-plugin,但我不知道如何在它们之间传递文件名

    编辑:在我将它分成3个模块之前,我让bash exec工作,但是java exec是新的,但我认为它应该和bash exec一样工作

1 个答案:

答案 0 :(得分:1)

(感谢Shinchan指出我正确的方向)

使用maven依赖插件,可以将输出jar从一个模块复制到另一个模块:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <id>copy</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>GROUP_ID</groupId>
                        <artifactId>OTHER_MODULE_NAME</artifactId>
                        <version>OTHER_MODULE_VERSION</version>
                        <type>jar</type>
                        <overWrite>true</overWrite>
                        <outputDirectory>${project.build.directory}/</outputDirectory>
                        <destFileName>FILE_FROM_OTHER_MODULE.jar</destFileName>
                    </artifactItem>
                </artifactItems>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>true</overWriteSnapshots>
            </configuration>
        </plugin>

这会在构建目录中生成一个名为“FILE_FROM_OTHER_MODULE.jar”的文件, 现在我可以将exec参数指向“FILE_FROM_OTHER_MODULE.jar”

相关问题