Deploying java web application with javadoc as welcome-file - amazon-web-services

I have created java web application. When i deploy my applicaton to server using tomcat7, i want to deploy my javadoc as welcome-file so when i go to root directory of app i want to see reference. But instead tomcate gives lots of 404 error. Here is my project structure;
And my web.xml is;
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<description>Multiple packages, separated by semicolon(;), can be specified in param-value</description>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>org.elhan.usermanager</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ServletAdaptor</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>javadoc/index.html</welcome-file>
</welcome-file-list>
</web-app>
How can i fix this?

nevermind. I solved the problem by moving javadoc contents to "Web Pages" directory. And in the web.xml file i changed javadoc/index.html with index.htmland deployed it. It works.

Related

Building a REST web service

I am trying to build a simple Web service.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>REST_service</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Jersey</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
This is my class:
package com.service.user;
import javax.ws.rs.*;
#Path("/user/service")
public class UserService
{
#PUT
#Path("/create")
public void createUser(){
}
#GET
public void getUser(){
System.out.println("Inside GET");
}
}
I am running it using this request: http://localhost:8080/REST_service/
And it starts fine. But when I go to call the GET request, it doesnt get called.
http://localhost:8080/REST_service/rest/user/service
I am very confused as to what's going wrong and not able to debug.
Any help appreciated!
You still need to tell jersey to scan your packages for your resource classes so it can register them.
<servlet>
<servlet-name>Jersey</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
com.service
</param-value>
</init-param>
<servlet>

Static resources not accessible in Jersey rest

I am having problem accessing my static resources in /project/resources/(css|js)/. I was able to access index.css in my css folder, but no other. I tried to find the root cause, changed regex expressions and messed up everything. Now I am not able to access even index.css now. Please find details below -
File structure -
webapp
|____ resources
| |____ css
| |____ js
|
|____ WEB-INF
|____ jsp
web.xml -
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>REST Web Application</filter-name>
<filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.restui</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.mvc.templateBasePath.jsp</param-name>
<param-value>/WEB-INF/jsp/</param-value>
</init-param>
<init-param>
<param-name>jersey.config.servlet.filter.staticContentRegex</param-name>
<param-value>/(resources/(css|js))|(WEB-INF/jsp)/*.*</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.server.mvc.jsp.JspMvcFeature</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>REST Web Application</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
I tried to find solutions on net but nothing was useful. Hoping for the useful solution.
Thanks in advance.
The jersey.config.servlet.filter.staticContentRegex property should work if you are using Jersey 2.x.
I believe your static resources are only on resources folder.
Try this:
<init-param>
<param-name>jersey.config.servlet.filter.staticContentRegex</param-name>
<param-value>/resources/(css|js)/.*</param-value>
</init-param>

Is it a REST web service?

I am working on a legacy application which have a .war with following structure (and I want to add my servlet in this war)
myApp.war
- axis2-web (Downloaded from http://ws.apache.org/axis2/download/1_1/download.cgi)
- META-INF
-- MANIFEST.MF
- WEB-INF
-- classes (But it don't have any `.class` file , it have `log4j.properties` file)
-- conf (Contains `axis2.xml`)
-- lib (contains many jars)
-- modules
-- services (Some `.aar` files)
-- web.xml
Here is the web.xml file
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Apache-Axis2</display-name>
<servlet>
<servlet-name>AxisServlet</servlet-name>
<display-name>Apache-Axis Servlet</display-name>
<servlet-class>
org.apache.axis2.transport.http.AxisServlet</servlet-class>
<!--<init-param>-->
<!--<param-name>axis2.xml.path</param-name>-->
<!--<param-value>/WEB-INF/conf/axis2.xml</param-value>-->
<!--<param-name>axis2.xml.url</param-name>-->
<!--<param-value>http://localhot/myrepo/axis2.xml</param-value>-->
<!--<param-name>axis2.repository.path</param-name>-->
<!--<param-value>/WEB-INF</param-value>-->
<!--<param-name>axis2.repository.url</param-name>-->
<!--<param-value>http://localhot/myrepo</param-value>-->
<!--</init-param>-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>AxisRESTServlet</servlet-name>
<display-name>Apache-Axis Servlet (REST)</display-name>
<servlet-class>
org.apache.axis2.transport.http.AxisRESTServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>AxisAdminServlet</servlet-name>
<display-name>Apache-Axis AxisAdmin Servlet (REST)</display-name>
<servlet-class>
org.apache.axis2.transport.http.AxisAdminServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AxisRESTServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisAdminServlet</servlet-name>
<url-pattern>/axis2-admin/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>/axis2-web/index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/axis2-web/Error/error404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/axis2-web/Error/error500.jsp</location>
</error-page>
</web-app>
Is it a REST web service ? I Googled and found some tutorials on REST which says REST services have services.xml file but I couldn't find it in my application. I want to integrate my servlet in above war so what will be the right way to do it ?
PS: Please let me know if I am missing anything.
As I understand RESTFUL WS approach that the it has a traditional http request and response with get ,post ,put or delete operations directly passed to the web service and so the response doesn't have any special format (JSON-RPC,SOAP) .
For example , if we write simple code some-service.jsp and put this code on our server
the restful tells us to call the service using any http client passing it the required params
and then we will get the service response .
Now if your application meets this , it would be RESTful .
Note : there are no any specific implementation techniques for REST it is just a WS approach
hope this would help you

Problem with cometd and jetty 6 / 7

I'm trying to get started with cometd (http://cometd.org/) and jetty 6 or 7, but I seem to be having problems. I've got an ant script that packages my code up into a war with the cometd 1.1.1 binaries and jetty binaries that are appropriate to the version of jetty I deploy the war to (so 7.1.2.v20100523 binaries when I deploy to jetty 7.1.2.v20100523 and 6.1.24 when I deploy to 6.1.24). I first tried getting a setup with version 7.1.2.v20100523, but when I tried to deploy I got a very long stack trace sample of which is:
2010-05-26 15:32:12.906:WARN::Problem processing jar entry org/eclipse/jetty/util/MultiPartOutputStream.class
java.io.IOException: Invalid resource
at org.eclipse.jetty.util.resource.URLResource.getInputStream(URLResource.java:204)
at org.eclipse.jetty.util.resource.JarResource.getInputStream(JarResource.java:113)
at org.eclipse.jetty.annotations.AnnotationParser$2.processEntry(AnnotationParser.java:575)
at org.eclipse.jetty.webapp.JarScanner.matched(JarScanner.java:152)
at org.eclipse.jetty.util.PatternMatcher.matchPatterns(PatternMatcher.java:82)
at org.eclipse.jetty.util.PatternMatcher.match(PatternMatcher.java:64)
at org.eclipse.jetty.webapp.JarScanner.scan(JarScanner.java:75)
at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:587)
at org.eclipse.jetty.annotations.AbstractConfiguration.parseWebInfLib(AbstractConfiguration.java:107)
at org.eclipse.jetty.annotations.AnnotationConfiguration.configure(AnnotationConfiguration.java:68)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:992)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:579)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:381)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:36)
at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:182)
at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:497)
at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:135)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileChanged(ScanningAppProvider.java:77)
at org.eclipse.jetty.util.Scanner.reportChange(Scanner.java:490)
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:355)
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:306)
at org.eclipse.jetty.util.Scanner$1.run(Scanner.java:258)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
2010-05-26 15:32:12.907:WARN::Problem processing jar entry org/eclipse/jetty/util/MultiPartWriter.class
java.io.IOException: Invalid resource
at org.eclipse.jetty.util.resource.URLResource.getInputStream(URLResource.java:204)
at org.eclipse.jetty.util.resource.JarResource.getInputStream(JarResource.java:113)
at org.eclipse.jetty.annotations.AnnotationParser$2.processEntry(AnnotationParser.java:575)
at org.eclipse.jetty.webapp.JarScanner.matched(JarScanner.java:152)
at org.eclipse.jetty.util.PatternMatcher.matchPatterns(PatternMatcher.java:82)
at org.eclipse.jetty.util.PatternMatcher.match(PatternMatcher.java:64)
at org.eclipse.jetty.webapp.JarScanner.scan(JarScanner.java:75)
at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:587)
at org.eclipse.jetty.annotations.AbstractConfiguration.parseWebInfLib(AbstractConfiguration.java:107)
at org.eclipse.jetty.annotations.AnnotationConfiguration.configure(AnnotationConfiguration.java:68)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:992)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:579)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:381)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:36)
at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:182)
at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:497)
at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:135)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileChanged(ScanningAppProvider.java:77)
at org.eclipse.jetty.util.Scanner.reportChange(Scanner.java:490)
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:355)
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:306)
at org.eclipse.jetty.util.Scanner$1.run(Scanner.java:258)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
2010-05-26 15:32:12.907:WARN::Problem processing jar entry org/eclipse/jetty/util/Attributes.class
java.io.IOException: Invalid resource
at org.eclipse.jetty.util.resource.URLResource.getInputStream(URLResource.java:204)
at org.eclipse.jetty.util.resource.JarResource.getInputStream(JarResource.java:113)
at org.eclipse.jetty.annotations.AnnotationParser$2.processEntry(AnnotationParser.java:575)
at org.eclipse.jetty.webapp.JarScanner.matched(JarScanner.java:152)
at org.eclipse.jetty.util.PatternMatcher.matchPatterns(PatternMatcher.java:82)
at org.eclipse.jetty.util.PatternMatcher.match(PatternMatcher.java:64)
at org.eclipse.jetty.webapp.JarScanner.scan(JarScanner.java:75)
at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:587)
at org.eclipse.jetty.annotations.AbstractConfiguration.parseWebInfLib(AbstractConfiguration.java:107)
at org.eclipse.jetty.annotations.AnnotationConfiguration.configure(AnnotationConfiguration.java:68)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:992)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:579)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:381)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:36)
at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:182)
at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:497)
at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:135)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileChanged(ScanningAppProvider.java:77)
at org.eclipse.jetty.util.Scanner.reportChange(Scanner.java:490)
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:355)
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:306)
at org.eclipse.jetty.util.Scanner$1.run(Scanner.java:258)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Seemed to go through all the jetty binaries and complain about each class file.
When I tried to deploy to 6.1.24 I got
org.mortbay.util.MultiException[java.lang.NoClassDefFoundError: org/eclipse/jetty/util/ajax/JSON$Source, java.lang.NoClassDefFoundError: org/eclipse/jetty/util/thread/ThreadPool]
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:656)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
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 org.mortbay.xml.XmlConfiguration.main(XmlConfiguration.java:985)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.mortbay.start.Main.invokeMain(Main.java:194)
at org.mortbay.start.Main.start(Main.java:534)
at org.mortbay.start.Main.start(Main.java:441)
at org.mortbay.start.Main.main(Main.java:119)
My web.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>cometd</servlet-name>
<servlet-class>org.cometd.server.continuation.ContinuationCometdServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cometd</servlet-name>
<url-pattern>/cometd/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>initializer</servlet-name>
<servlet-class>uk.co.dubit.nexus.comet.BayeuxInitializer</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- <filter>
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/cometd/*</url-pattern>
</filter-mapping> -->
</web-app>
note cross origin filter is commented out. The class didn't seem to exist when I tried to run on 6.1.24 (which as far as I understand is the correct behaviour, yes?).
Sorry for the noob question but does anyone know what I'm doing wrong here?
Regards,
Tom
ok seems there were a couple of problems to work out here. Firstly the version of jetty I was bundling in my war needed to change. I switched to 7.0.2.v20100331. Secondly I had to change the deployment descriptor
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>cometd</servlet-name>
<servlet-class>org.cometd.server.continuation.ContinuationCometdServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cometd</servlet-name>
<url-pattern>/cometd/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>initializer</servlet-name>
<servlet-class>uk.co.dubit.nexus.comet.BayeuxInitializer</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<filter>
<filter-name>continuation</filter-name>
<filter-class>org.eclipse.jetty.continuation.ContinuationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>continuation</filter-name>
<url-pattern>/cometd/*</url-pattern>
</filter-mapping>
</web-app>
And finally there's an extra step in deploying a war to jetty 6.1.24 (which is the version I got the code running on in the end), you have to place an XML descriptor for the war in the contexts/ directory. My descriptor looked like
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<configure class="org.mortbay.jetty.webapp.WebAppContext">
<Set name="contextPath">/cometd</Set>
<Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/nexus.war</Set>
</configure>
After that my servlet was accessible from the /cometd path listed in this descriptor.

Serving static content with jetty 7, using defaultservlet configured from web.xml

This is jetty 7 and xml configured, not embedded.
I'm trying to serve a static file, crossdomain.xml, to an app that connects to a datasource I run from jetty. To do this, I configured a servlet and its mapping thus:
<servlet>
<servlet-name>default </servlet-name>
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet </servlet-class>
<init-param>
<param-name>resourceBase </param-name>
<param-value>/foo/foo </param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>default </servlet-name>
<url-pattern>/* </url-pattern>
</servlet-mapping>
Sadly all I get are 404's. Any help would be much appreciated, btw the rest of my web.xm lfile looks like:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"version="2.5">
<servlet>
<servlet-name>cometd </servlet-name>
<servlet-class>org.cometd.server.continuation.ContinuationCometdServlet </servlet-class>
<load-on-startup>1 </load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cometd </servlet-name>
<url-pattern>/cometd/* </url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>default </servlet-name>
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet </servlet-class>
<init-param>
<param-name>resourceBase </param-name>
<param-value>/foo/foo </param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>default </servlet-name>
<url-pattern>/* </url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>initializer </servlet-name>
<servlet-class>com.foo.research.Initializer </servlet-class>
<load-on-startup>2 </load-on-startup>
</servlet>
<filter>
<filter-name>cross-origin </filter-name>
<filter-class>org.eclipse.jetty.servlets.CrossOriginFilter </filter-class>
</filter>
<filter-mapping>
<filter-name>cross-origin </filter-name>
<url-pattern>/cometd/* </url-pattern>
</filter-mapping>
</web-app>
I had the same issue; here is a snippet that works (Jetty 6.1.22).
I basically replaced org.eclipse with org.mortbay and removed the
resourceBase parameter (but see below). And this actually ends up in my web.xml file inside my WAR file:
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>foo.bar.MyServlet</servlet-class>
<display-name></display-name>
<description>The smallest Servlet ever!</description>
</servlet>
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.mortbay.jetty.servlet.DefaultServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/static/*</url-pattern>
</servlet-mapping>
Then, you have to put your static files in the "static" directory in your
WAR file. Like this (just to make it clear):
ROOT.war
|_ WEB-INF/
|_ static/
If you want to put your static files elsewhere (but still map them under
the /static/ URI), you can use the resourceBase parameter to specify the
directory, just like you did.
Jetty's documentation helped me to understand this a little bit better:
http://docs.codehaus.org/display/JETTY/Servlets+Bundled+with+Jetty