4

exec:execゴールを使用してmavenexecプラグインを使用してJavaプログラムを実行しようとしています。
クラスパスにjarを追加する必要があります(sun tools jar)。
includePluginDependenciesはexec:javaの目標に対してのみ機能するため、引数セクションに手動で追加することを考えましたが、基本クラスパスに連結する方法が見つかりませんでした。問題は、jarがシステムスコープとして定義されているため、mavenがそれをランタイムクラスパスに追加せず、手動で追加する必要があることです。
誰かがコマンドラインからそうする方法を知っているなら、それはさらに良いです。よろしくお願いします、
Avner

  • 以下のプラグインセクションを見ることができます

            <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <dependencies>
                <dependency>
                    <groupId>com.sun</groupId>
                    <artifactId>tools</artifactId>
                    <scope>system</scope>
                    <systemPath>${JDK_HOME}/lib/tools.jar</systemPath>
                </dependency>
                <dependency>
                    <groupId>${project.groupId}</groupId>
                    <artifactId>myArtifact</artifactId>
                    <version>1.0</version>
                </dependency>
            </dependencies>
            <configuration>
                <executable>java</executable>
                <arguments>
                    <argument>-classpath</argument>
                    <classpath/>                        
                    <argument>com.mycompany.MyMainClass</argument>
                </arguments>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    
4

3 に答える 3

2

最終的に私はmaven-antrun-pluginを使用することに決めたので、ここに可能な代替ソリューションがあります。

<configuration>
<target>
    <property name="runtime_classpath" refid="maven.runtime.classpath"/>

    <java classname="com.mycompany.MyClass"
            fork="true"
            spawn="false"
            failonerror="true"
            maxmemory="512m" >

        <classpath>
            <pathelement path="${runtime_classpath}" />
            <pathelement path="${JDK_HOME}/lib/tools.jar" />
        </classpath>
        <arg value="${ant.param1}" />
        <arg value="${ant.param2}" />
        <arg value="${ant.param3}" />
        <arg value="${ant.param4}" />
        <arg value="${ant.param5}" />
    </java>
</target>
</configuration>
于 2012-09-09T07:18:20.370 に答える
1

追加してみる

<argument>-Xbootclasspath/a:${env.JAVA_HOME}/lib/tools.jar</argument>

コマンドラインから、追加します

-Dexec.args="-Xbootclasspath/a:$JAVA_HOME/lib/tools.jar"

もう 1 つのオプションは、tools.jar をシステムの依存関係として宣言してから、exec プラグインのスコープを「システム」に設定することです。参照: exec-maven-plugin - classpathScope

于 2012-09-07T19:04:30.667 に答える
1

CLASSPATH 環境変数の設定を試すことができます。

于 2012-09-06T03:39:19.160 に答える