Reputation: 631
I have a war file containing:
META-INF
|___MANIFEST.MF
WEB-INF
|___web.xml
|___classes
|____servlet
|____StarterServlet.class
my web.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>WAR</display-name>
<servlet>
<display-name>Starter Servlet</display-name>
<servlet-name>StarterServlet</servlet-name>
<servlet-class>servlet.StarterServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>StarterServlet</servlet-name>
<url-pattern>/starter</url-pattern>
</servlet-mapping>
</web-app>
And my servlet code is:
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class StarterServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
public void init(ServletConfig servletConfiguration) throws ServletException {
super.init(servletConfiguration);
System.out.println("SERVLET STARTED!");
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("DOGET!");
PrintWriter printWriter = response.getWriter();
printWriter.println("Hello world");
}
}
Also, my runtime name is: "war", so i am going to lookup for my context root with this URL:
http://localhost:8080/war/starter.
The main problem is that my servlet does not get initialized, and i can't see any trace on jboss log files,although my war gets deployed correctly.
Where am i doing it wrong?
Thanks
Upvotes: 0
Views: 1418
Reputation: 631
Thanks to the answer of @wirnse i got the solution.
Name and runtime name must always contain the extension of the file which is being deployed.
For example: application.war must have name and runtime name following this pattern:
^[a-zA-Z]+.(ear|war|jar)
myapp.war or war.war
Upvotes: 0
Reputation: 1136
If you want to change the context root to http://localhost:8080/war/ you have to add a jboss-web.xml to WEB-INF/jboss-web.xml
with content:
<jboss-web>
<context-root>war</context-root>
</jboss-web>
Also leave the default values in Name
and Runtime Name
when you upload the war.
In the jboss log you should then see a message with Registered web context: /war
Upvotes: 1