views:

757

answers:

2

I'm using Eclipse 3.5, Maven 2, m2eclipse and Tomcat 6. So i create Maven project for archetype webapp. This is pom.xml:

<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/maven-v4_0_0.xsd"&gt;  
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.itransition</groupId>
    <artifactId>hello</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>hello Maven Webapp</name> 
    <url>http://maven.apache.org&lt;/url&gt;

    <!-- tools.jar dependency -->    
    <profiles>
        <profile>
            <id>default-tools.jar</id>
            <activation>
                <property>
                    <name>java.vendor</name>
                    <value>Sun Microsystems Inc.</value>
                </property>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>com.sun</groupId>
                    <artifactId>tools</artifactId>
                    <version>1.5.0</version>
                    <scope>system</scope>
                    <systemPath>${java.home}/../lib/tools.jar</systemPath>
                </dependency>
            </dependencies>
        </profile>
    </profiles>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>2.1.8.1</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>hello</finalName>
    </build>
</project>

So then i want to deploy my web application to Tomcat. What I need to do? Maven install don't help. But if I create war by Maven install, i can import it to eclipse and deploy it to Tomcat by "Add and remove..." in server popup.

+1  A: 

This problem can be resolved by using the Tomcat plugin for Maven. Its homepage has got extensive documentation concerning the configuration of the plugin and deployment of war files.

pkainulainen
Sorry for stupid question, but how can I get this plugin? I don't find any download page.
No problem. When you add the plugin configuration to your pom.xml file, Maven will download the plugin and its dependencies automatically.
pkainulainen
403 probably means that you should add the username and password needed to access the tomcat manager application to your pom.xml file. The Tomcat side of the configuration is described here: http://tomcat.apache.org/tomcat-5.5-doc/manager-howto.html#Configuring%20Manager%20Application%20Access Also, see Section named 'Using Different Tomcat Manager Authentication Details' from here:http://mojo.codehaus.org/tomcat-maven-plugin/configuration.html
pkainulainen
A: 

So then i want to deploy my web application to Tomcat. What I need to do? Maven install don't help. But if I create war by Maven install, i can import it to eclipse and deploy it to Tomcat by "Add and remove..." in server popup.

Since you are using m2eclipse, my recommendation would be to deploy your application using the WTP. Assuming you have the Maven integration for WTP feature installed (from m2eclipse extras) and Tomcat configured as Server, just right-click on your project and select Run > Run on Server...

Another option would be to run your application on Jetty (yes, I know that this is not what you're asking for but this is very valid option if you don't want to use the WTP). Add the following snippet to your pom:

<project>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.10</version>
      </plugin>
    </plugins>
  </build>
</project>

And simply run mvn jetty:run to start an embedded Jetty server and deploy your application on it.

The same can be achieved for Tomcat using the Tomcat Maven Plugin but unless you want to deploy to a remote Tomcat (see the Usage page), I don't see any advantage over the Maven Jetty Plugin.

During development, I would use the first option (deploy with the WTP).

Pascal Thivent
When I deploy application with WTP, I have 404 error on pages.
@fatkh You have another problem somewhere or you are doing something wrong but I guarantee that it works for the rest of us.
Pascal Thivent