java 无法在上下文路径中将 Web 应用程序部署到服务器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4250153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failing to Deploy Web App to server at context path?
提问by Chris
I have a simple Jersey jax rs hello world application that I am trying to deploy to my tomcat server so i can call the resource url and check and see if it gives me the required output but when i set the context path in the web.xml it doesnt deploy to the server it does however when i take the servlet information out and just leave a blank web.xml meaning this must be my problem. Here is the contents of my web.xml.
我有一个简单的 Jersey jax rs hello world 应用程序,我试图将它部署到我的 tomcat 服务器,以便我可以调用资源 url 并检查它是否提供了所需的输出,但是当我在 web.xml 中设置上下文路径时它不会部署到服务器,但是当我取出 servlet 信息并只留下一个空白的 web.xml 时,它会部署到服务器,这意味着这一定是我的问题。这是我的 web.xml 的内容。
`<!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>Web App</display-name>
<servlet-name>ServletContainer</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletContainer</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
</web-app>
As requested here is the stacktrace of the error
根据这里的要求是错误的堆栈跟踪
[INFO] [war:war {execution: default-war}]
[INFO] Packaging webapp
[INFO] Assembling webapp[app1] in [C:\Users\leothYearUni\Project\app1\target\app1]
[INFO] Processing war project
[INFO] Copying webapp resources[C:\Users\leothYearUni\Project\app1\src\main\webapp]
[INFO] Webapp assembled in[170 msecs]
[INFO] Building war: C:\Users\leothYearUni\Project\app1\target\app1.war
[INFO] [tomcat:redeploy {execution: default-cli}]
[INFO] Deploying war to http://localhost:8080/app1
[INFO] OK - Undeployed application at context path /app1
[INFO] FAIL - Failed to deploy application at context path /app1
If anyone has any ideas or workarounds this would be much appreciated Thank you Chris
如果有人有任何想法或解决方法,这将不胜感激谢谢克里斯
采纳答案by Brian
Kind of drive-by answering here, but I note a hanging end tag in the middle of your web.xml:
在这里直接回答,但我注意到 web.xml 中间有一个悬挂的结束标记:
</servlet>
</servlet>
this would stop it parsing....
这将阻止它解析....
回答by matt b
First of all, if something is failing deployment, the first hint at a solution is to look at the logs of the application server to answer the question "Why is this failing?"
首先,如果部署失败,解决方案的第一个提示是查看应用服务器的日志来回答“为什么会失败?”的问题。
Things don't just "fail", they will give error messages and exceptions and stacktraces and information about what is actually occurring. Attempting to guess why something fails with none of this knowledge amounts to just guesswork.
事情不仅会“失败”,还会给出错误消息、异常和堆栈跟踪以及有关实际发生情况的信息。试图在没有这些知识的情况下猜测为什么某些事情会失败,这只是猜测。
As a guess, make sure that the class com.sun.jersey.spi.container.servlet.ServletContainer
is on the classpath of the web application (i.e. in the WEB-INF/lib
directory).
作为猜测,请确保该类com.sun.jersey.spi.container.servlet.ServletContainer
位于 Web 应用程序的类路径中(即在WEB-INF/lib
目录中)。
回答by Stepan Yakovenko
One of the possible reasons for this is this sort of entry in ant
造成这种情况的可能原因之一是 ant 中的这种条目
<zipfileset dir="./mywebcontent/" prefix="/" />
remove prefix="/", it spoils your archive
删除前缀 =“/”,它会破坏您的存档
回答by Nav
In my case, it was because when working on https://netbeans.org/kb/docs/web/ajax-quickstart.htmltutorial, I didn't tick "add information to the deployment descriptor (web.xml)" during the create new servlet wizard.
Although I deleted that servlet and created the servlet again, this time ticking the checkbox, I think this is what caused my 'context.xml' to contain <Context antiJARLocking="true" path="/MyAjaxApp"/>
which caused the error.
就我而言,这是因为在处理https://netbeans.org/kb/docs/web/ajax-quickstart.html教程时,我没有勾选“向部署描述符(web.xml)添加信息”创建新的 servlet 向导。
虽然我删除了那个 servlet 并再次创建了 servlet,这次勾选了复选框,但我认为这是导致我的 'context.xml' 包含<Context antiJARLocking="true" path="/MyAjaxApp"/>
导致错误的原因。
So when I changed the line to <Context antiJARLocking="true" path="/AutoCompleteServlet"/>
, everything worked fine.
因此,当我将线路更改为 时<Context antiJARLocking="true" path="/AutoCompleteServlet"/>
,一切正常。
回答by Chris
Turns out there was some confusion about the web.xml files i was editing , and when found the correct web.xml and sorted the hanging servlet tag this sorted the problem . Thank you everyone for all your help and patience as I am completely new to maven.
结果发现我正在编辑的 web.xml 文件有些混乱,当找到正确的 web.xml 并对挂起的 servlet 标签进行排序时,问题就解决了。感谢大家的帮助和耐心,因为我是 maven 的新手。