简体   繁体   中英

Installing Jetty on Ubuntu, getting com.sun.tools.javac.Main is not on the classpath

I'm trying to install Jetty on Ubuntu 11.04 and I'm about to pull my hair out. I'm running into a classpath issue. I start Jetty with start.jar, setting JAVA_HOME to point to the JDK.

/usr/share/jetty$ export JAVA_HOME=/usr/lib/jvm/java-6-sun
/usr/share/jetty$ java -jar start.jar 

[...]

com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-6-sun-1.6.0.26/jre"

    at org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:127)
...

Notice that it's ignoring the JAVA_HOME I set, and using the jre. I've also tried this:

java -classpath /usr/lib/jvm/java-6-sun/lib/tools.jar -jar start.jar

Same error message. It's not finding, com.sun.tools.javac.Main, and that's in tools.jar.

Down in the guts of Jetty, when it's trying to compile my .jsp's, it's using Ant, and that's doing some kind of classloader tricks, I'm guessing. Does anyone know what the secret is to telling this cranky software where my tools.jar file can be found??

Note that I've gotten the same error with the sun jdk and openjdk and, yes, I do have the JDK installed, not just the JRE.

The way apt-get installs java, the java binary that's part of the JDK points into the JRE. Like this:

ls -alph /usr/lib/jvm/java-6-sun/bin/java
lrwxrwxrwx 1 root root 15 2011-10-25 18:48 /usr/lib/jvm/java-6-sun/bin/java -> ../jre/bin/java

I'm guessing that Jetty, Jasper or Ant does some trickery to try and find tools.jar based on the location of the java executable, and that's what's failing here.

Any clues are greatly appreciated. Thanks!

您可以将tools.jar添加到JVM的引导类路径中:

java -Xbootclasspath/p:/usr/lib/jvm/java-6-sun/lib/tools.jar -jar start.jar

Though you're exporting a new JAVA_HOME environment variable, I don't see that you're also exporting a new PATH environment variable. You're probably still picking up the java executable from the original Java home location. Try including export PATH=$JAVA_HOME/bin:$PATH .

Since comments are kinda unreadable on SO, here's the info you asked for:

$ lsb_release -s -c
natty

I installed the sun JDK like so, but remember that the same error occurred with openjdk.

sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo apt-get update
sudo apt-get -y install sun-java6-jdk
sudo update-alternatives --config java

I'm pretty sure configuring the environment that I run start.jar in is on the wrong track, since I tried pretty hard with that and got nowhere.

Jetty call's Jasper, which calls the Ant task that compiles your JSPs. In the source for Ant's org/apache/tools/ant/taskdefs/Javac.java you can see where it's setting the classpath.

My problem likely has something to do with passing or not passing environment variables or maybe java systems properties down that chain.

An Ugly Solution

Just for laughs, I created a symbolic link from /usr/lib/jvm/java-6-sun/lib/tools.jar to /usr/lib/jvm/java-6-sun/jre/lib/ext. Ugly, huh? But, it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM