Wednesday, January 23, 2013

maven tomcat plugin

maven: v3.x
tomcat: v6.0.32
maven tomcat plugin: v2.0  (http://tomcat.apache.org/maven-plugin-2.0/)

1. add maven tomcat plugin in pom.xml


<build>
<!-- apache tomcat maven plugin -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<url>http://localhost:8080/manager</url>
<server>demo-dev</server>
<path>/demo</path>
</configuration>
</plugin>
<!-- maven plugin to skip test while building -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>

2. edit .m2\settings.xml


<server>
    <id>demo-dev</id>
            <username>manager</username>
            <password>tomcat</password>
        </server>

3. make sure above username/password is configured in %tomcat%/conf/tomcat-users.xml

<role rolename="manager"/>
<user username="manager" password="tomcat" roles="manager"/>

4. Configure JNDI
4.1 configure JNDI in %tomcat%/conf/server.xml   (refer to http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html)


4.2 Alternatively,configure JNDI in  META-INF/context.xml for individual project, for example,

<Context>

    <!-- maxActive: Maximum number of database connections in pool. Make sure you
         configure your mysqld max_connections large enough to handle
         all of your db connections. Set to -1 for no limit.
         -->

    <!-- maxIdle: Maximum number of idle database connections to retain in pool.
         Set to -1 for no limit.  See also the DBCP documentation on this
         and the minEvictableIdleTimeMillis configuration parameter.
         -->

    <!-- maxWait: Maximum time to wait for a database connection to become available
         in ms, in this example 10 seconds. An Exception is thrown if
         this timeout is exceeded.  Set to -1 to wait indefinitely.
         -->

    <!-- username and password: MySQL username and password for database connections  -->

    <!-- driverClassName: Class name for the old mm.mysql JDBC driver is
         org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
         Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
         -->
    
    <!-- url: The JDBC connection url for connecting to your MySQL database.
         -->

  <Resource name="jdbc/demodb" auth="Container" type="javax.sql.DataSource"
               maxActive="100" maxIdle="30" maxWait="10000"
               username="{userid}" password="{password}" driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql://localhost:3306/demodb"/>

</Context>

4.3 configure <resource-ref> element in web.xml

<resource-ref>
<description>JNDI config to access MySQL Database</description>
<res-ref-name>jdbc/demodb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>


No comments:

Post a Comment