maven工程用jetty启动的通过代码启动
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;
public class Sample {
public static void main(String[] args) throws Exception {
Server service = new Server();
Connector connector = new SelectChannelConnector();
connector.setPort(8082);
connector.setHost("localhost");
service.setConnectors(new Connector[] { connector });
WebAppContext context = new WebAppContext("src/main/webapp", "/webmavenjetty");
service.addHandler(context);
service.setStopAtShutdown(true);
service.setSendServerVersion(true);
service.start();
service.join();
}
}
run as -> java application之后正常
通过浏览器访问时如下错:
ERROR: Javac exception
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)
at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:924)
at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:757)
at org.apache.jasper.compiler.AntJavaCompiler$JavacObj.run(AntJavaCompiler.java:355)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
其实就是tools.jar这个jar文件没找到
先查看JDK的安装目录下是否有tool.jar文件(Java\jdk1.7.0_45\lib)
再把tool.jar加到jre中,如下:
Eclipse window -> Preferences ->Java ->Installed JRES -> Edit ->Add External JARS 添加tool.jar