1

I have project in maven. Here is main pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>pl.derp</groupId>
    <artifactId>parent</artifactId>
    <packaging>pom</packaging>
    <version>1.0.0-SNAPSHOT</version>
    <modules>
        <module>server</module>
        <module>shared</module>
        <module>web</module>
    </modules>

    <properties>
        <gwtVersion>2.7.0</gwtVersion>
        <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <tomcat.webport>8083</tomcat.webport>
        <tomcat.ajpport>8182</tomcat.ajpport>
        <tomcat.context>/parent</tomcat.context>

        <hibernate.version>4.3.7.Final</hibernate.version>
        <mysql.connector.version>5.1.21</mysql.connector.version>

        <slf4j.version>1.6.4</slf4j.version>
        <spring.version>3.0.5.RELEASE</spring.version>
        <guice.version>3.0</guice.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-servlet</artifactId>
            <version>${gwtVersion}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.google.gwt</groupId>
            <artifactId>gwt-user</artifactId>
            <version>${gwtVersion}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
            <classifier>sources</classifier>
            <scope>test</scope>
        </dependency>
        <!-- DB related dependencies -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.connector.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.12.1.GA</version>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.182</version>
        </dependency>

        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
        </dependency>

        <!-- Custom formats -->
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>org.jadira.usertype</groupId>
            <artifactId>usertype.extended</artifactId>
            <version>3.2.0.GA</version>
        </dependency>


        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
            <version>${spring.version}</version>
        </dependency>


        <!-- Tests -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>

    </dependencies>


    <build>

        <defaultGoal>clean install tomcat7:run-war-only</defaultGoal>

        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>gwt-maven-plugin</artifactId>
                <version>${gwtVersion}</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
            </plugin>

            <!-- IDE -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.7</version>  <!-- Note 2.8 does not work with AspectJ aspect path -->
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>false</downloadJavadocs>
                    <wtpversion>2.0</wtpversion>
                    <additionalBuildcommands>
                        <buildCommand>
                            <name>org.eclipse.jdt.core.javabuilder</name>
                            <arguments>
                            </arguments>
                        </buildCommand>
                        <buildCommand>
                            <name>com.google.gdt.eclipse.core.webAppProjectValidator</name>
                            <arguments>
                            </arguments>
                        </buildCommand>
                        <buildCommand>
                            <name>com.google.gwt.eclipse.core.gwtProjectValidator</name>
                            <arguments>
                            </arguments>
                        </buildCommand>
                    </additionalBuildcommands>
                    <additionalProjectnatures>
                        <projectnature>com.google.gwt.eclipse.core.gwtNature</projectnature>
                    </additionalProjectnatures>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.0</version>
                <configuration>
                    <path>${tomcat.context}</path>
                    <port>${tomcat.webport}</port>
                    <ajpPort>${tomcat.ajpport}</ajpPort>
                    <systemProperties>
                        <JAVA_OPTS>-XX:MaxPermSize=256m</JAVA_OPTS>
                    </systemProperties>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

I am using tomcat7-maven-plugin as You can see in pom.xml.

To start server I use command: maven clean install tomcat7:run-war-only

But unfortunately when I do any change in server side/tier code I have to stop server and run it again, which takes a lot of time, cause of: test runs, full compilation, all permutation compilation (it is gwt app, so it compiles java code to js code for each web browser)...

How can I set up auto code replace/hot swap on runtime, that I don't have to restart and recompile my project, when I do one little change?

I would speed up my developing process.

Please give me some help.

masterdany88
  • 5,041
  • 11
  • 58
  • 132

2 Answers2

0

I guess the bit which takes the longest is the GWT complication. If you are doing all your development with a single browser, you can tell GWT to only compile the permutation for that browser. See this question and accepted answer to see how. That should cut down your build time.

Also, you can tell Maven to skip tests. This is not really a practice I'd recommend, but if you are really sure your change is trivial, or does not involve Java code, then use the Maven switch -DskipTests

If you change only involves resources such as HTML, CSS, JS, JSP etc then you can just copy them directly to $tomcat_home/webapps/yourapp and Tomcat will pick them up, no build needed. Take care to always have the newest version in your source code.

Finally, the Tomcat plugin should not require a Tomcat restart. Try

mvn tomcat7:redeploy
Community
  • 1
  • 1
NickJ
  • 9,380
  • 9
  • 51
  • 74
  • I should use this command: `mvn tomcat7:redeploy` when I have running tomcat server? Will this update my java classes on server? – masterdany88 Sep 22 '15 at 08:59
  • I am getting an error: `[ERROR] Could not find goal 'redeploy' in plugin org.apache.tomcat.maven:tomcat7-maven-plugin:2.0 among available goals exec-war-only, deploy-only, shutdown, run-war-only, run, deploy, run-war, exec-war, help -> [Help 1] ` – masterdany88 Sep 22 '15 at 09:04
  • Strange. Try `mvn tomcat7:deploy` instead. Tomcat should be running. It will update whole application on Tomcat. Automatically runs `package` first, so will recompile everything. – NickJ Sep 22 '15 at 09:12
  • Dosen't work. Maybe we should continue on chat: https://chat.stackoverflow.com/rooms/90302/how-to-runn-tomcat7-maven-plugin-that-server-code-changes-will-be-updated-immedi? – masterdany88 Sep 22 '15 at 09:17
  • I have a working pom with tomcat plugin, but it's on my pc at home - I'll edit my answer later with the working plugin. – NickJ Sep 22 '15 at 10:15
0

The tomcat7-maven-plugin is not made for that purpose, use an IDE (IntelliJ, Eclipse, Netbeans,...) or a dynamic classloader like JRebel.

Stefan
  • 12,108
  • 5
  • 47
  • 66
  • I use Eclipse IDE. But I don't know how to integrate Tomcat Maven plugin with Eclipse Servers. Can You give me some thoughts about it? Is it possible? What do You mean by: `Use IDE`? – masterdany88 Sep 22 '15 at 12:17
  • Eclipse already has an ability to publish resources to a server. No need to use the Plugin explicitly. Open "Windows" -> "Views" -> "Servers". Add your Tomcat and a Project and press play. http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jst.server.ui.doc.user%2Ftopics%2Ftomcat.html – Stefan Sep 22 '15 at 12:20
  • I've tried to do this. Unfortunately my Maven project doesn't work with Eclipse servers. How should I configure Maven or Eclipse to make them work together? – masterdany88 Sep 22 '15 at 12:22
  • I know what IDE is. I'just can not make them two work together. Maven starts his own eclipse server using maven goals. Please help me on that. – masterdany88 Sep 22 '15 at 12:23