Reputation: 11
I've been attempting to embed Jetty and Quercus in my application for the past few months, but I haven't been successful yet. I'm using Jetty version 6.1.26 and Quercus 4.0.25.
I've packaged the following jars with my application's: jetty-6.1.26.jar, jetty-util-6.1.26.jar, and servlet-api-2.5-20081211.jar which I copied from the jetty/lib directory.
Here's my code that runs on its own thread:
public void run(){
try{
server = new Server(Plugin.port);
WebAppContext wac = new WebAppContext();
wac.setWar(Plugin.resourceBase);
wac.setDescriptor(Plugin.resourceBase + "WEB-INF/web.xml");
wac.setContextPath("/");
wac.setParentLoaderPriority(true);
server.setHandler(wac);
server.setStopAtShutdown(true);
server.start();
Plugin.instance.getLogger().log(Level.INFO, "Started web server at port " + Plugin.port);
}catch(Exception e){
Plugin.instance.getLogger().log(Level.SEVERE, "Cannot start web server at port " + Plugin.port + "!");
Plugin.instance.getLogger().log(Level.SEVERE, e.getMessage());
}
}
In the resource base directory, I have a WEB-INF folder that contains a web.xml file as well as Quercus' WEB-INF/lib and /licenses. The jars that are in the lib folder are cdi-16.jar, javaee-16.jar, javamail-141.jar, and resin.jar.
The web.xml has the following under its web app tags:
<servlet>
<servlet-name>Quercus Servlet</servlet-name>
<servlet-class>com.caucho.quercus.servlet.QuercusServlet</servlet-class>
<init-param>
<param-name>license-directory</param-name>
<param-value>WEB-INF/licenses</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Quercus Servlet</servlet-name>
<url-pattern>*.php</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.php</welcome-file>
</welcome-file-list>
When I start the program, I get this message in the console:
10:31:46 [SEVERE] 2013-03-03 10:31:46.570:INFO:/:Unavailable javax.servlet.UnavailableException: Servlet class com.caucho.quercus.servlet.QuercusServlet is not a javax.servlet.Servlet
I can then access HTML files on the Jetty server, but when I try to access PHP ones, I get a message saying
javax.servlet.UnavailableException: Servlet class com.caucho.quercus.servlet.QuercusServlet is not a javax.servlet.Servlet
at org.mortbay.jetty.servlet.ServletHolder.checkServletType(ServletHolder.java:362)
at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:243)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:736)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1282)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:518)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:499)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:224)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at me.jsn_man.WebServer.WebServer.run(WebServer.java:52)
If anyone can offer help that would be much appreciated.
Also, if you have suggestions of what versions of Jetty and Quercus I should be using, that would also be helpful. I'm only using Jetty 6 because that's the version which had the most documentation about embedding.
Upvotes: 0
Views: 820
Reputation: 36
Try removing javaee-16.jar from the Quercus war. I'll remove it from future Quercus distributions. Thanks.
Upvotes: 0
Reputation: 24630
Recently I did the same.
I then extract the war to a folder quercus in the current working directory without any modifications.
Setup in embedded Jetty like this:
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setWar("./quercus");
server.setHandler(webapp);
Upvotes: 0