2

通常どおり「mvn package」を実行し、すべての手順が完了したら、Jar ユーティリティを呼び出して、パッケージ化されたコード (jar ファイルまたは war ファイル) のファイルパスを引数として渡す必要があります。

このユーティリティは、コマンド ラインから次のように呼び出されます。

java -jar Utility.jar -filepath {新しい jar/war ファイルのパス}

その最終ステップをビルド プロセスに統合したいと考えています。これを実現するために pom.xml ファイルを変更するにはどうすればよいですか?

4

2 に答える 2

1

Mavenexecプラグインをご覧ください。それの実行をパッケージフェーズにバインドして(パッケージによって定義された組み込みのバインディングの後に実行されます)、引数 "-jar Utility.jar -filepath $ {project.build.directory]を使用してjava(実行可能ファイル)を実行できます。 } / $ {project.artifactId}-$ {project.version}-${project.packaging}"結果は次のようになります。

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <id>run jar utility</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>java</executable>
                            <arguments>
                                <argument>-jar</argument>
                                <argument>Utility.jar</argument>
                                <argument>-filepath</argument>
                                <argument>${project.build.directory}/${project.build.finalName}.${project.packaging}</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

ただし、この呼び出しはプラットフォーム固有です。これを少し改善して、「exec」の代わりに「java」を使用することができます(そのUtility.jarでメインクラス名を指定する必要があります)

使用する予定のユーティリティについて説明すると、それを行うためのよりクロスプラットフォームの方法がある可能性があります(たとえば、maven antrunプラグイン) 。

于 2012-12-24T18:15:03.170 に答える
0

@radaiが提案したものからexec-maven-pluginを実行する別の方法を次に示します。代わりにこの方法でそれを行うことができるなら、私はそれをお勧めします。

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <inherited>false</inherited>
            <executions>
                <execution>
                    <goals>
                        <goal>java</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!--I don't want my project's dependencies in the classpath-->
                <includeProjectDependencies>false</includeProjectDependencies>
                <!--Just include the dependencies that this plugin needs.  IE: the Utility dependencies-->
                <includePluginDependencies>true</includePluginDependencies>
                <executableDependency>
                    <groupId>com.utility</groupId>
                    <artifactId>Utility</artifactId>
                </executableDependency>
                <mainClass>com.utility.MyMainClass</mainClass>
                <!--You may be able to use a variable substitution for pathToJarFile.  Try it and see-->
                <commandlineArgs>-filepath pathToJarFile</commandlineArgs>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>com.utility</groupId>
                    <artifactId>Utility</artifactId>
                    <version>1.0-SNAPSHOT</version>
                </dependency>
            </dependencies>
        </plugin>
于 2012-12-24T20:12:26.360 に答える