1
votes

I use Eclipse Mars. I have a server runtime configured in eclipse for Tomcat8.

I created a maven webapp project with a very simple servlet that only does a sysout() statement when the (overriden) init runs.

I'm trying to run the webapp in tomcat, hoping to see the sysout statement when the servlet is initialized. However, I'm under the impression none of my java classes are actually being compiled/build and put under the web-inf folder because tomcat starts fine, but I see no sysouts.

When I go to localhost:8080/HelloWorld/ I expect my servlet's doGet() method to run (I also put a sysout in that method), but instead I get a 404.

Here's my project layout (standard maven): enter image description here

And my pom (I removed the irrelevant parts). I believe the build plugins are not executed when I start my tomcat.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" ...">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.company.group</groupId>
    <artifactId>artifact</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>
    <name>HelloWorld</name>

    <properties>
        ...
    </properties>

    <dependencies>
        ...
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <warName>HelloWorld</warName>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

And my web.xml enter image description here

Here's the init method from my servlet:

@Override
public void init(ServletConfig servletconfig) throws ServletException
{
    System.out.println("sysout servlet");
}

And of course I added the project to my tomcat config:

enter image description here

1
where you are checking the output? - Prashant
I don't. When I run a spring or struts webapp from eclipse, the eclipse-tomcat plugin just knows what to do and builds/compiles all classes and puts them in web-inf/classes. I'm now trying to achieve the same with a maven webapp - user1884155

1 Answers

1
votes

[http://bigleap.co.in/corp/2013/06/running-maven-project-within-eclipse-on-tomcat/][1] . you exactly need to set goals to compile and run maven project in eclipse tomact. two goals clean:instal and tomact7:run.