14

I'm on Windows XP, using Eclipse Indigo, Tomcat 6.0.33, and have the Maven plugin installed. (Using Maven 3.0.3 on my system). I have Tomcat showing up in my Eclipse servers list, but I can't figure out a one click way to deploy my WAR project to the Tomcat server. When I right click my project and select "Run" there are many Maven options (e.g. "Maven Install"), but none builds and then deploys my project to Tomcat.

Any help along these lines? Thanks, - Dave

Dave
  • 15,639
  • 133
  • 442
  • 830
  • For running tomacat, you should use WTP. You can make m2eclipse and WTP work together. Take a look at the answer to this question: [m2eclipse-and-eclipse-wtp](http://stackoverflow.com/questions/1822290/m2eclipse-and-eclipse-wtp) – Nr9 Oct 11 '11 at 15:33

6 Answers6

30

see below link for details

http://mojo.codehaus.org/tomcat-maven-plugin/deployment.html

Alternatively, search for tomcat:run and you can use it directly

EDIT:

Run/Debug Configurations

Double click maven build, a new configuration will be created

put ${project_loc} for base directory

put tomcat:run for goals

give an appropriate name for yourself at the top

Apply and run/debug using your new configuration

EDIT2:

The link has been changed to below one: http://tomcat.apache.org/maven-plugin-trunk/tomcat7-maven-plugin/ (Thanks @Lucky)

fmucar
  • 14,361
  • 2
  • 45
  • 50
  • That's great but when you say I can use "tomcat:run" directly, are you talking about from Eclipse? Can you be more specific about what I need to do in Eclipse to set that up? - Dave – Dave Oct 11 '11 at 14:44
  • 1
    Awesome. I really appreciate the step-by-step method you list here. – Dave Oct 11 '11 at 15:42
  • The link for plugin has been changed to http://tomcat.apache.org/maven-plugin-trunk/tomcat7-maven-plugin/ – Lucky May 07 '16 at 11:35
  • Use [this](https://www.youtube.com/watch?v=o-Y15VPw5KA) video, very self explanatory. – Nicholas K Feb 23 '19 at 13:40
4

within Eclipse, you can run the project by doing the following:

In the servers view, create a server (right-click, new Server, Tomcat) Add the project to the server (right-click the server, add & remove, select the project) Start the server - the server will start & deploy the app

The trick to this is that the server does not deploy the packaged app in the tomcat webapps directory, it deploys an exploded version into a directory under the plug-ins directory of the eclipse installation.

To specifically do the maven packaging and deploy to the external tomcat istance (external to eclipse), use the tomcat-maven-plugin, as specified by fmucar

TrueDub
  • 5,000
  • 1
  • 27
  • 33
  • in eclipse mars(4.5.2) it runs in a tmp folder located within your workspace .metadata\.plugins\org.eclipse.wst.server.core – kyle Aug 25 '17 at 03:35
0
  1. Run Configurations : Select Base Directory of our maven base project directory.
  2. Give Goals as tomcat7:run to run application and tomcat7:deploy for deploy tomcat7:deploy
  3. In maven settings.xml, give server configuration as below under <servers> tag

    <servers>
        <server>
            <id>TomcatServer</id>
            <username>admin</username>
            <password>admin</password>
        </server>
    <servers>
    
  4. In the parameters section of run configurations give parameter maven.tomcat.port and give any required port number. Ex: 7777

  5. In the pom.xml provide tomcat plugin as below under <build> tag

    <plugins>  
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
    
        <configuration>
            <url>http://localhost:7777/manager/html</url>
            <server>TomcatServer</server>
            <username>admin</username>
            <password>admin</password>
        </configuration>
        <executions>
        <execution>
        <id>tomcat-run</id>
        <goals>
            <goal>run</goal>
        </goals>
        <phase>pre-integration-test</phase>
        <configuration>
            <port>7777</port>
        </configuration>
    </execution>
      </executions>
    </plugin>
    
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
0

within Eclipse, you can run the project by doing the following:

In the servers view, create a server (right-click, new Server, Tomcat) Add the project to the server (right-click the server, add & remove, select the project) Start the server - the server will start & deploy the app

The trick to this is that the server does not deploy the packaged app in the tomcat webapps directory, it deploys an exploded version into a directory under the plug-ins directory of the eclipse installation.

To specifically do the maven packaging and deploy to the external tomcat istance (external to eclipse), use the tomcat-maven-plugin, as specified by fmucar


This I do not get because I don not want to add any maven plugin, I wanted to run it in simple manner like in old plain servlet programs we used to add server in server panel of eclipse and then over project we used to do Right Click and run on server.

Here how can I do it without adding maven plugin or please explain in details why maven plugin explicitly needed why I can not run server added to eclipse. I did steps given above(last solutions) but in that case server added to my eclipse do not starts instead of that server which was downloaded during maven plugin resolution (I am talking about tomcat:run command) process gets started.

Please explain in details as short answers only confuses I am beginner for maven.

0
  <build>
    <pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
        <configuration>
            <path>/</path>
            <contextReloadable>true</contextReloadable>
        </configuration>
        </plugin>
    </plugins>

</pluginManagement>
</build>

As Simple as that, just add above build tag under project tag in pom.xml and run by giving tomcat:run goal command in maven run configuration in eclipse.

Jan Černý
  • 1,268
  • 2
  • 17
  • 31
vic
  • 29
  • 9
0

In pom.xml add this dependency

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided </scope>
    </dependency>

Then right click on your project and select run as -> Spring boot app.

S14321K
  • 220
  • 3
  • 19