我尝试将我创建的servlet部署到Glassfish应用程序服务器,我似乎遇到了一些绊脚石。代码部署到auto deploy文件夹,并且一旦部署,以下内容将写入日志文件:
[#|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.|#]
所以没有明显的错误,但之后我从访问servlet应绑定的路径获得404。我需要经历另一个步骤吗?
我的WAR文件中的web.xml如下所示:
<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>
答案 0 :(得分:1)
此部署存在一些问题。首先,需要将第二个配置文件包含在名为WEB-INF
的{{1}}目录中。其内容需要与以下内容类似:
sun-web.xml
似乎有可能比这更复杂(见the documentation)。
其次,我必须更改<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 8.1 Servlet 2.4//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_4-1.dtd">
<sun-web-app error-url="">
<context-root>/MyServlet </context-root>
</sun-web-app>
文件的标题,因此它会相应地读取:
web.xml
请注意标题,表明这是servlet规范2.4。
最后,您似乎无法直接访问此servlet;您必须将<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<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>
(或servlet特定名称)添加到路径的开头。因此,要访问此servlet,您需要访问MyServlet/
。
答案 1 :(得分:0)
我修改了web.xml;我只是为ords添加了config目录的完整路径。
<display-name>Oracle Application Express Listener</display-name>
<context-param>
<param-name>config.dir</param-name>
<!-- Enter the location where configuration settings should be stored -->
<param-value>/odata/apps/ords/config</param-value>
</context-param>
无论是否存在sun-web.xml,它都能正常工作。