Jspresso webapp using tomcat-maven-plugin

Here is how to setup your Jspresso project to run using “tomcat7-maven-plugin“.

TIPS : This is useful for example if your using IntelliJ IDEA Community

 

1/ Configure tomcat files

Choose location for tomcat configuration, for example “yourproject/webapp/conf“, to store tomcat configuration files :

  • context.xml
  • jaas.config
  • log4j.xml
  • etc.

NB : You can checkout HRSample from GITHUB to get sample files : https://github.com/jspresso/hrsample-ce

 

2/ Setup your web app pom.xml 

  • Adapt project name (i.e replace “yourproject” by your project name)
  • Adapt the dependencies according to your needs (database dependency and others)
  • Adapt Java opts and other system properties
  • Put 3 slashes in the file: url below if you run under windows
    <build> 
        <plugins> 
           <plugin> 
                <groupId>org.apache.tomcat.maven</groupId> 
                <artifactId>tomcat7-maven-plugin</artifactId> 
                <version>2.1</version> 
                <configuration> 
                    <port>8080</port> 
                    <path>/yourproject-webapp</path> 
                    <warDirectory> ${project.build.directory}/yourproject-webapp</warDirectory> 
                    <useTestClasspath>false</useTestClasspath> 
                    <useSeparateTomcatClassLoader>true</useSeparateTomcatClassLoader>
                    <contextFile>conf/context.xml</contextFile>
 
                    <systemProperties> 
                        <JAVA_OPTS>-Xms256m -Xmx512m -Xmx1024m -XX:MaxPermSize=256m</JAVA_OPTS> 
                        <skipTests/> 
                        <disableAttachJavadocs/> 
                        <disableAttachSources/> 
                        <java.security.auth.login.config>${project.basedir}/conf/jaas.config</java.security.auth.login.config> 
                        <log4j.configuration>file://${project.basedir}/conf/log4j.xml</log4j.configuration> 
                    </systemProperties> 
                </configuration> 
                <dependencies> 
                    <dependency> 
                        <groupId>org.hsqldb</groupId> 
                        <artifactId>hsqldb</artifactId> 
                        <version>${hsql.version}</version> 
                    </dependency> 
                    <dependency> 
                        <groupId>log4j</groupId> 
                        <artifactId>log4j</artifactId> 
                        <version>${log4j.version}</version> 
                    </dependency> 
                    <dependency> 
                        <groupId>org.slf4j</groupId> 
                        <artifactId>slf4j-log4j12</artifactId> 
                        <version>${slf4j.version}</version> 
                    </dependency> 
                </dependencies> 
            </plugin> 
        </plugins> 
    </build>


 

3/ Build your project using “mvn install”

This has to be done once only, all artefact will be packaged and stored into your maven repository… only the “core” and “webapp” module will be rebuild at launch time. See bellow.

 

4/ Create a run configuration

Here is an IntelliJ IDEA example for HRSample app :

  • Go to menu “Run” then “Edit configurations…”
  • Click “+” button on top left and select “Maven”
  • Feed the formular as bellow
    • Command line :
    • tomcat7:run-war -pl webapp
    • Add a “Before launch” to install core and web app before launching tomcat :
      install -pl  core,webapp -P!generate-ddl-scripts -DskipTests -DdisableAttachJavadocs -DdisableAttachSources

 

5/ Run your app !

It’s done !

 

Categories: IDE

Leave a Reply