在你的应用里使用Jetty嵌入式

Jetty嵌入式的支持jsp的web container,我在一个港股行情系统里嵌入了jetty来通过http监控系统状况。

Jetty的pom依赖库

<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>6.1.19</version>
</dependency>
<dependency>
<groupId>tomcat</groupId>
<artifactId>jasper-compiler</artifactId>
<version>5.5.12</version>
</dependency>
<dependency>
<groupId>tomcat</groupId>
<artifactId>jasper-runtime</artifactId>
<version>5.5.12</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>

jetty没有自己的compiler,所以需要依赖tomcat的jar。同时它需要ant的compiler,否则会报错:

java.lang.IllegalStateException: No Java compiler available
at org.apache.jasper.JspCompilationContext.createCompiler(JspCompilationContext.java:224)...

所以需要加入ant

需要tools.jar
否则会提示
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)

所以把JAVA_HOME/lib/tools.jar加入到启动命令里即可,如果是在eclipse或者其他的IDE里启动,把tools.jar加到JRE的lib里。

启动代码
public void run()
{
try {
server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(this.getPort());
server.addConnector(connector);

ContextHandlerCollection contexts = new ContextHandlerCollection();
server.setHandler(contexts);
WebAppContext webapp = new WebAppContext();
webapp.setDefaultsDescriptor(getDescriptor());
webapp.setResourceBase(getResourceBase());
webapp.setContextPath(getContextPath());
contexts.addHandler(webapp);

/** 启动 */
server.start();
System.out.println("Monitor Server listening on : " + this.getPort());
server.join();
} catch (Exception e) {
e.printStackTrace();
}
}
  • 提供Oracle管理/故障处理/优化/安装/RAC/备份恢复技术服务,提供专业的Oracle培训和咨询服务
  • 专业论坛 http://www.inthirties.com
  • 技术博客 http://blog.csdn.net/inthirties
  • 个人站点 http://blog.inthirties.com

你可能感兴趣的:(oracle,exception,server,嵌入式,compiler,webapp)