Maven Ant BuildException с maven-antrun-plugin ... не удалось найти компилятор javac - PullRequest
6 голосов
/ 10 января 2011

Я пытаюсь заставить Maven вызывать сборку ANT для какого-то устаревшего кода.Сборка муравья строится правильно через муравья.Однако, когда я вызываю его с помощью плагина maven ant, происходит сбой со следующей ошибкой:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run      (default) on project CoreServices: An Ant BuildException has occured: The following error occurred while executing this line:
[ERROR] C:\dev\projects\build\build.xml:158: The following error occurred while executing this line:
[ERROR] C:\dev\projects\build\build.xml:62: The following error occurred while executing this line:
[ERROR] C:\dev\projects\build\build.xml:33: The following error occurred while executing this line:
[ERROR] C:\dev\projects\ods\build.xml:41: Unable to find a javac compiler;
[ERROR] com.sun.tools.javac.Main is not on the classpath.
[ERROR] Perhaps JAVA_HOME does not point to the JDK.
[ERROR] It is currently set to "C:\bea\jdk150_11\jre"

Мой Javac существует в C: \ bea \ jdk150_11 \ bin, и это работает для всех остальных вещейЯ не уверен, где Maven получает эту версию JAVA_HOME.JAVA_HOME в Windows переменные среды установлены в C: \ bea \ jdk150_11 \, как и должно быть.

Код Maven, который я использую для вызова build.xml:

<build>
   <plugins>
    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-antrun-plugin</artifactId>
     <version>1.6</version>

     <executions>
          <execution>
            <phase>install</phase>
            <configuration>

              <target>
    <ant antfile="../build/build.xml" target="deliver" >
    </ant>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
    </plugin>
   </plugins>
  </build>

1 Ответ

16 голосов
/ 10 января 2011

Первое: почему вы выполняете скрипт ANT в фазе install, а не в compile?

Второе: ваша проблема может быть вызвана тем, что Maven выполняет JRE вместо JDK, несмотря на то, что ваш JAVA_HOME указывает на JDK. Чтобы исправить это, вы должны вручную настроить зависимости для maven-antrun-plugin. Это всего лишь пример:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <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>
    <executions>
        <execution>
            <phase>compile</phase>
            <configuration><target><ant/></target></configuration>
            <goals><goal>run</goal></goals>
        </execution>
    </executions>
</plugin>
...