Chris
Chris

Reputation: 863

Failing to Deploy Web App to server at context path?

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.

 `<!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\leo\4thYearUni\Project\app1\target\app1]
[INFO] Processing war project
[INFO] Copying webapp resources[C:\Users\leo\4thYearUni\Project\app1\src\main\webapp]
[INFO] Webapp assembled in[170 msecs]
[INFO] Building war: C:\Users\leo\4thYearUni\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

Upvotes: 6

Views: 18855

Answers (5)

Nav
Nav

Reputation: 20658

In my case, it was because when working on https://netbeans.org/kb/docs/web/ajax-quickstart.html tutorial, 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.

So when I changed the line to <Context antiJARLocking="true" path="/AutoCompleteServlet"/>, everything worked fine.

Upvotes: 0

Stepan Yakovenko
Stepan Yakovenko

Reputation: 9206

One of the possible reasons for this is this sort of entry in ant

<zipfileset dir="./mywebcontent/" prefix="/" />

remove prefix="/", it spoils your archive

Upvotes: 1

Chris
Chris

Reputation: 863

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.

Upvotes: 1

matt b
matt b

Reputation: 139931

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).

Upvotes: 2

Brian
Brian

Reputation: 56

Kind of drive-by answering here, but I note a hanging end tag in the middle of your web.xml:

</servlet>

this would stop it parsing....

Upvotes: 1

Related Questions