如何运行tomcat7-maven-plugin,该服务器代码更改将立即更新 [英] How to run tomcat7-maven-plugin, that server code changes will be updated immediately

查看:113
本文介绍了如何运行tomcat7-maven-plugin,该服务器代码更改将立即更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在maven中有项目.这是主要的pom.xml:

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>

我正在使用tomcat7-maven-plugin,如您在pom.xml中看到的那样.

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

要启动服务器,请使用以下命令:maven clean install tomcat7:run-war-only

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

但是不幸的是,当我在服务器端/层代码中进行任何更改时,我必须停止服务器并再次运行它,这需要很多时间,原因是:测试运行,完全编译,全部排列编译(这是gwt应用程序,因此它为每个Web浏览器将Java代码编译为js代码)...

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?

我会加快开发过程.

请给我一些帮助.

推荐答案

我猜花时间最长的是GWT并发症.如果您使用单个浏览器进行所有开发,则可以告诉GWT仅编译该浏览器的排列.请参阅此问题和已接受的答案以了解操作方法.那应该减少您的构建时间.

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.

此外,您可以告诉Maven跳过测试.我实际上不建议您这样做,但是如果您确实确定所做的更改是微不足道的,或者不涉及Java代码,请使用Maven开关-DskipTests

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

如果更改仅涉及HTML,CSS,JS,JSP等资源,则可以直接将它们直接复制到$ tomcat_home/webapps/yourapp中,Tomcat会选择它们,不需要构建.注意始终在源代码中始终具有最新版本.

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.

最后,Tomcat插件不需要重新启动Tomcat.试试

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

mvn tomcat7:redeploy

这篇关于如何运行tomcat7-maven-plugin,该服务器代码更改将立即更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆