0

我们在一个奇怪的 unix-ish 开发平台下使用 maven 时遇到了一些问题。maven 编译器插件抱怨tools.jar在默认安装的 java 中由于奇怪的 JDK/JRE 混淆而无法找到。

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:
      2.5.1:compile (default-compile) on project xyz: Fatal error compiling:
      tools.jar not found: our-java-home-dir/../lib/tools.jar -> [Help 1]

../lib/tools.jar应该是真的lib/tools.jar。java安装(Java 7)似乎是一个JDK,但不知何故java将它检测为只是一个JRE,因此造成了混乱。在查看 java 代码在做什么时,它一定认为我们安装了 JRE,并且期望JAVA_HOME指向jre真正的JAVA_HOME. 再多的复制、符号链接或其他黑客行为似乎都无法让我们../liblib.

我们已经在 intertubes 上看到了很多类似的问题,但没有一个有太大帮助。我们无法像在其他平台上那样重新安装 Java 或任何解决方案,但它应该是一个完整的 JDK,并且在bin子目录中包含所有 j*tools。

4

1 回答 1

0

... tools.jar not found: our-java-home-dir/../lib/tools.jar -> [Help 1]

One solution for us that seems to work was is to the force the tools.jar file onto the boot-class-path of the maven command by hand. We used the following program to dump the current value of the boot-class-path:

public class Main {
    public static void main(String[] args) {
        System.out.println("Boot-class-path=" +
            System.getProperty("sun.boot.class.path"));
    }
}

Then we modified the end of the mvn script in $M2_HOME/bin/mvn to insert the -Xbootclasspath option:

$MAVEN_OPTS \
    -Xbootclasspath:existing-boot-class-path-here:${JAVA_HOME}/lib/tools.jar \
    -additional-maven-options-go-here...

We added the tools.jar entry to the end of the value spat out by the main program above. There are other maven options that you need to leave in there of course.

Hope this helps someone else.

于 2018-04-10T00:24:30.050 回答