40

統一されたMavenビルドを使用して、既存のJavaプロジェクトの束を改造しています。maven-antrun-plugin各プロジェクトは成熟しており、次のように既存の実行に使用しているすべての Ant ベースのビルドを確立してbuild.xmlいます。

        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <configuration>
                        <tasks>
                            <ant antfile="build.xml" target="compile" />
                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

ビルドを実行mvn compileすると、次のメッセージが表示されて失敗します。

[INFO] An Ant BuildException has occured: The following error occurred 
       while executing  this line:
build.xml:175: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Java\jdk1.6.0_13\jre"

私を困惑させるのは

  1. 私はJAVA_HOME=C:\Java\jdk1.6.0_13自分の環境セットアップの一部として持っており、mvn.batそれが実行されると、それはまさに私が得ている値ですが、エラーメッセージに表示されるように、C:\Java\jdk1.6.0_13\jre
  2. すべてを実行ant compileすると、問題なくコンパイルされます

おそらくmaven-antrun-plugin次のようなことをするということset JAVA_HOME=%JAVA_HOME%\jreですか?バッチ/ビルド ファイルを検索しましたが、その変更が発生した場所が見つかりません

4

2 に答える 2

22

それは、受け入れられた回答における外部リンクのマイナス面です。Codehaus が閉鎖されたため、解決策はなくなりました。参考までに、リンクの背後にあるコンテンツを以下に示します。基本的には、<dependencies>...</dependencies>ブロックを antrun プラグインにコピーするだけで済みます...

maven-antrun-plugin は、実行全体の JAVA_HOME が JDK であっても、JAVA_HOME を JDKのjreサブディレクトリに設定して ant を実行します。プロジェクト レベルで JDK の tools.jar の依存関係を作成する方法については、別の場所にドキュメントがありますが、これはプラグインである antrun には役立ちません。次のプロファイルがその役割を果たします。パスの「..」は、「jre」ディレクトリを越えて lib ディレクトリに移動します。

<profiles>
      <profile>
          <id>tools.jar</id>
          <build>
            <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-antrun-plugin</artifactId>
              <dependencies>
                <dependency>
                  <groupId>com.sun</groupId>
                  <artifactId>tools</artifactId>
                  <version>1.5.0</version>
                  <scope>system</scope>
                  <systemPath>${java.home}/../lib/tools.jar</systemPath>
                </dependency>
              </dependencies>
            </plugin>
            </plugins>
          </build>
      </profile>
于 2015-08-12T15:37:47.303 に答える
21

ant build.xml ファイルに次のプロパティ定義を追加することで、これを修正できました。

<property name="build.compiler" value="extJavac"/>
于 2013-03-14T12:18:30.677 に答える