I have created a maven project with basic archetype. created a web.xml under /webapp/WEB-INF .
web.xml is given as follows
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<welcome-file-list>
<welcome-file>home.html</welcome-file>
</welcome-file-list>
</web-app>
pom.xml is as shown below.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tvashtra</groupId>
<artifactId>HelloWorld</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp/jsp-api -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
home.html is present in webapp folder but outside WEB-INF directory. along with this created a servlet by extending HttpServlet class like below.
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/Login")
public class ServletOne extends HttpServlet
{
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException
{
try {
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Mukesh Khanna</title>");
out.println("</head>");
out.println("<body>");
out.println("<h2>My name is Ashish Parab</h2>");
out.println("</body>");
out.println("</html>");
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
I ensure that jboss http port is working on 9080 port
now after doing all this, i deployed the war however nothing seems to work.
*
* *
http://localhost:9080/HelloWorld/Login * both above links displaying message as "the site can't be reached"
upon googling/youtubing, i have come across many examples where they are using Tomcat server as plugin but i don't want that.
Thanks in advance
as suggested in below comment, i created jboss-web.xml and kept under WEB-INF i am using JBOSS 7 EAP and below is the content of jboss-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.jboss.com/xml/ns/javaee
http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
<context-root>/HelloWorld</context-root>
</jboss-web>
however still not able to hit the target http://localhost:9080/HelloWorld
there seems to be problem of multiple jboss instances running on a same machine.
followed the exact same procedure without jboss-web.xml
also removed servlet dependency from pom and added below one
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
it worked like a charm!