0
votes

My Project is Named "A" and my class is:

@WebServlet(urlPatterns={"/test/*"}) public class RequestHandler extends HttpServlet {

Maven plugin:

<plugin>
      <groupId>org.apache.tomcat.maven</groupId>
      <artifactId>tomcat7-maven-plugin</artifactId>
      </plugin>

Under src/main/webapp/WEB-INF/web.xml I've got

<?xml version="1.0" encoding="UTF-8"?>
<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"/>

Tomcat7 starts like this when running tomcat7:run:

Running war on http://localhost:8080/A

...

Aug 08, 2012 12:28:08 PM org.apache.coyote.AbstractProtocol init Information: Initializing ProtocolHandler ["http-bio-8080"] Aug 08, 2012 12:28:08 PM org.apache.catalina.core.StandardService startInternal Information: Starting service Tomcat Aug 08, 2012 12:28:08 PM org.apache.catalina.core.StandardEngine startInternal Information: Starting Servlet Engine: Apache Tomcat/7.0.25 Aug 08, 2012 12:28:08 PM org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment Information: No global web.xml found Aug 08, 2012 12:28:09 PM org.apache.coyote.AbstractProtocol start Information: Starting ProtocolHandler ["http-bio-8080"]

When I go to http://localhost:8080/A or http://localhost:8080/A/test I get an 404 from Tomcat7

What am I doing wrong?

1

1 Answers

0
votes

Delete the web.xml file.

Configure your pom.xml with:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.0-SNAPSHOT</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <configuration>
                <port>8080</port>
                <path>/</path>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.apache.tomcat.embed</groupId>
                    <artifactId>tomcat-embed-core</artifactId>
                    <version>7.0.29</version>
                </dependency>
            </dependencies>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <showDeprecation>true</showDeprecation>
                <showWarnings>true</showWarnings>
                <fork>true</fork>
            </configuration>
        </plugin>
    </plugins>
</build>
<pluginRepositories>
    <pluginRepository>
        <id>apache.snapshots</id>
        <name>Apache Snapshots</name>
        <url>http://repository.apache.org/content/groups/snapshots-group/</url>
    </pluginRepository>
</pluginRepositories>