I tried to deploy a servlet I have created to Glassfish application server, and I seem to have hit a bit of a stumbling block. The code deploys fine to the auto deploy folder, and once it’s deployed the following is written to the log file:
[#|2009-03-16T13:41:29.303+0000|INFO|sun-appserver2.1|javax.enterprise.system.tools.deployment|_ThreadID=23;_ThreadName=Timer-7;|[AutoDeploy] Selecting file /opt/glassfish-2.1.b60e/domains/imageTransformer/autodeploy/image-transformer.war for autodeployment.|#] [#|2009-03-16T13:41:29.304+0000|INFO|sun-appserver2.1|javax.enterprise.system.tools.deployment|_ThreadID=23;_ThreadName=Timer-7;|Autoundeploying application :image-transformer|#] [#|2009-03-16T13:41:29.360+0000|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=23;_ThreadName=Timer-7;| classLoader = WebappClassLoader delegate: true repositories: /WEB-INF/classes/ ----------> Parent Classloader: EJBClassLoader : urlSet = [] doneCalled = false Parent -> java.net.URLClassLoader@39cf701c |#] [#|2009-03-16T13:41:29.361+0000|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=23;_ThreadName=Timer-7;| SharedSecrets.getJavaNetAccess()=java.net.URLClassLoader$7@5e7408d9|#] [#|2009-03-16T13:41:29.487+0000|INFO|sun-appserver2.1|javax.enterprise.system.tools.deployment|_ThreadID=23;_ThreadName=Timer-7;|[AutoDeploy] Successfully autoundeployed : /opt/glassfish-2.1.b60e/domains/imageTransformer/autodeploy/image-transformer.war.|#] [#|2009-03-16T13:41:29.612+0000|INFO|sun-appserver2.1|javax.enterprise.system.tools.deployment|_ThreadID=23;_ThreadName=Timer-7;|deployed with moduleid = image-transformer|#] [#|2009-03-16T13:41:29.783+0000|INFO|sun-appserver2.1|javax.enterprise.system.tools.deployment|_ThreadID=23;_ThreadName=Timer-7;|[AutoDeploy] Successfully autodeployed : /opt/glassfish-2.1.b60e/domains/imageTransformer/autodeploy/image-transformer.war.|#]
So no obvious errors, but after that I get a 404 from accessing the path that the servlet should be bound to. Is there another step that I need to go through?
the web.xml in my WAR file looks like this:
<web-app> <servlet> <servlet-name>MyServlet</servlet-name> <servlet-class>my.servlet.MyServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>MyServlet</servlet-name> <url-pattern>/hello</url-pattern> </servlet-mapping> </web-app>
There were a couple of problems with this deployment. Firstly, there is a requirement for a second configuration file to be included in the
WEB-INFdirectory, namedsun-web.xml. Its contents need to be something along the lines of:It seems to have the potential to get a lot more complex than this (see the documentation).
Secondly, I had to change the header for the
web.xmlfile, so it read accordingly:Note the headers indicating that this is servlet spec 2.4.
Finally, it also seems that you can’t access this servlet directly; you have to prepend
MyServlet/(or the servlet specific name) to the beginning of the path. So to access this servlet requires you to visit/MyServlet/hello.