Friday, 15 November 2013

Run Web app on embedded tomcat7 through maven

Add the tomcat7 maven plugin to the build section of your pom
<build> 
  ...
  <plugin>
    <groupid>org.apache.tomcat.maven</groupid>
    <artifactid>tomcat7-maven-plugin</artifactid>
    <version>2.0</version>
    <systemproperties>
      <java_opts>-XX:MaxPermSize=2G -XX:PermSize=2G</java_opts>
    </systemproperties>
    <configuration>
      <contextfile>LocalDeployment/myApp.xml</contextfile>
    </configuration>
  </plugin>
  ...
</build>
Place the configuration under LocalDeployment/myApp.xml the LocalDeployment directory is at the root of the project at the same level as the pom.xml. This can be anywhere as long as you point to it correctly in the plugin configuration
<context path="/myapp" reloadable="false">
    <!-- some  envrionment variables --> 
    <environment name="nodeId" override="false" type="java.lang.String" value="node01">
    </environment>
</context>
To run the web app use the following maven goals
mvn tomcat7:run           //run the project without building a war file
mvn tomcat7:run-war-only  //finds a war file in project and runs it
mvn tomcat7:run-war       //build and run a war file for current project
more goals can be found Here

To Debug in IntelliJ idea

Simply right click on any goal in the maven Projects tab Then under plugins->tomcat7 right click on a goal and select debug

To Debug in Eclipse

We need to first run tomcat listening for debug connections
Right click on project --> Run as maven build ... --> Enter goal: tomcat7:run
Select JRE Tab,
Enter in Vm Args: -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044

Now to connect to the debug port (1044)
Right click on project -->  debug configuration
Set Project: to your project
Set connection type to: "SOCKET ATTACH"
Set Host to: localhost
Set Port: 1044 and then press debug

No comments:

Post a Comment