Andrzej Czerwoniec
Andrzej Czerwoniec

Reputation: 203

Deploying maven project to tomcat server

I have some problems with my maven project in Eclipse (webapp archetype). I wrote a simple appliaction with a single .jsp and a servlet. .jsp pages work fine but accessing a servlet results in a Class not found exception. I think the problem is that maven (and also eclipse) deploys the servlet class as Servlet.java and not Servlet.class (in the wtpwebapps > .. > WEB_INF > classes >> etc. ).

The same code written as a Dynamic Web Application works fine because servlet is deployed by Eclipse with a .class extension.

I would like to stick with a Maven project so could you give me any hint on how to fix that?

Upvotes: 0

Views: 1354

Answers (3)

Niklas P
Niklas P

Reputation: 3507

If you run mvn tomcat7:deploy then maven is searching for a running tomcat server as configured within the pom.xml:

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <server>TomcatServer</server>
        <username>USERNAME</username>
        <password>PASSWORD</password>
        <url>http://localhost:8080/manager/text</url>
        <path>/training</path>
    </configuration>
</plugin>

As you can see in the url the manager application is called for deployment (manager application is installed per default within a tomcat, but NOT within a tomcat within eclipse because eclipse uses it's own tomcat-webapp-folder (wptwebapp)).

Anyway, if you want to use this kind of deployment outside of eclipse, you have to create a user within the tomcat-users.xml with the roles manager-gui and manager-script.

Upvotes: 1

Andrzej Czerwoniec
Andrzej Czerwoniec

Reputation: 203

It was my fault. I put my source code into src/main/resources and not src/main/java - thats why it wasn't compiled.

I would still like to know why maven doesn't deploy the application to wtpwebapps but the main issue is fixed now, thanks for help !

Upvotes: 1

Schaka
Schaka

Reputation: 772

Tomcat supplies servlet.jar. You need to put it in your pom.xml as <scope>provided</scope>.

That being said, Eclipse/Maven should not deploy servlet as a Java class file. It is a whole library provided by Tomcat which should NOT be compiled to a single class. You absolutely cannot have 2 servlet-api or servlet.jars in your packaged *.war file (the lib folder under webapps).

Also, it would probably help noting which ClassNotFoundException is being thrown. What class is missing? Because that sounds like your JSP version is referencing a class that isn't in the automatically deployed servlet-api jar Tomcat7 offers (3.0).

Upvotes: 1

Related Questions