I'm trying to run a Jetty web framework from main(...)
that loads a spring web context which loads JSPs at runtime. This works great from the command line using mvn exec:java
on OSX and Linux. However on Windows, running Cygwin, I cannot get it to fully work.
The application loads and the web-context seems to build fine. However when the first JSP page is rendered the JVM goes to compile it on the fly and throws the following error/exception:
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]
...
I've done a ton of web searches and tried a number of things before posting.
JAVA_HOME
variable is set correctly.tools.jar
file does exist under %JAVA_HOME%/lib/tools.jar
.JAVA_HOME
path is in Program Files
and I was worried about the space but replacing it with Progra~1
does not seem to work either.mvn
shell script under Cygwin as well as the mvn.bat
script under DOS but both fail similarly.Anyone else had this problem? Do I need to change the classpath
to specifically add a dependency to the tools.jar
somehow? Maybe something added to the pom.xml
? Thanks in advance.
com.sun.tools.javac.Main is not on the classpath.
I'm not sure this is the right solution but I found a workaround from this answer:
Using javah maven-antrun-plugin with jdk 1.7, classes.jar became tools.jar
I also utilized this answer: JDK tools.jar as maven dependency
I ended up adding a specific dependency for Windows in the pom which added the tools.jar
specifically to the classpath:
<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>
This adds a dependency only if the OS family is windows
. The system-path ../
is necessary in the path because ${java.home}
ends up as $JAVA_HOME/jre
for some reason. The version
didn't seem to matter since 1.7 and 1.6 seemed to work.
Hope this helps other folks.