1

我正在尝试从main(...)加载一个在运行时加载 JSP 的 Spring Web 上下文运行一个 Jetty Web 框架。mvn exec:java这在 OSX 和 Linux 上使用命令行非常有效。但是在运行 Cygwin 的 Windows 上,我无法让它完全工作。

应用程序加载并且网络上下文似乎构建良好。然而,当第一个 JSP 页面被渲染时,JVM 会即时编译它并抛出以下错误/异常:

org.apache.tools.ant.BuildException: 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
    at org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:105) ~[gwt-dev-2.5.1.jar:na]
    at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:924) ~[gwt-dev-2.5.1.jar:na]
    at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:757) ~[gwt-dev-2.5.1.jar:na]
    at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:382) [gwt-dev-2.5.1.jar:na]
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:472) [gwt-dev-2.5.1.jar:na]
    ...

在发布之前,我已经进行了大量的网络搜索并尝试了很多事情。

  1. JAVA_HOME变量设置正确。
  2. 我已经确定它指向 JDK 而不是JRE。该tools.jar文件确实存在于%JAVA_HOME%/lib/tools.jar.
  3. JAVA_HOME路径在里面Program Files,我担心空间,但用它替换它Progra~1似乎也不起作用。
  4. 我们已经尝试过mvnCygwin 下的 shell 脚本和mvn.batDOS 下的脚本,但都失败了。

还有其他人有这个问题吗?我是否需要更改classpath以以某种方式专门添加依赖项tools.jar?也许添加了一些东西pom.xml?提前致谢。

4

1 回答 1

0

com.sun.tools.javac.Main 不在类路径中。

我不确定这是正确的解决方案,但我从这个答案中找到了解决方法:

在 jdk 1.7 中使用 javah maven-antrun-plugin,classes.jar 变成了 tools.jar

我也利用了这个答案:JDK tools.jar as maven dependency

我最终在 pom 中为 Windows 添加了一个特定的依赖项,该依赖项专门添加tools.jar到了类路径中:

<profiles>
    <profile>
        <id>windows</id>
        <activation>
            <activeByDefault>false</activeByDefault>
            <os>
                <family>windows</family>
            </os>
        </activation>
        <dependencies>
            <dependency>
                <groupId>com.sun</groupId>
                <artifactId>tools</artifactId>
                <version>1.6</version>
                <scope>system</scope>
                <systemPath>${java.home}/../lib/tools.jar</systemPath>
            </dependency>
        </dependencies>
    </profile>
</profiles>

仅当操作系统系列为windows. 系统路径../在路径中是必要的,因为由于某种原因${java.home}最终会结束。$JAVA_HOME/jreversion似乎并不重要,因为 1.7 和 1.6 似乎工作。

希望这对其他人有所帮助。

于 2014-02-19T15:07:31.443 回答