9

我目前正在使用带有 maven-war-plugin 的 maven 3.x。对于开发人员构建,我希望能够使用 war:exploaded 目标,但只能复制已更改的资源。有没有办法做到这一点?

我一直在查看文档,但无法在当前版本中找到执行此操作的方法,但曾经(在旧的 maven 1.x 版本中)有一个属性 maven.war.resources.overwrite会允许这样做。

谢谢。

4

2 回答 2

1

我不知道使用 maven-war-plugin 执行此操作的方法,但如果您的 IDE 支持它,您可以让 IDE 自动部署更改。例如,Eclipse 的 Web 工具平台支持 Tomcat 的这个特性。但是,如果您的构建过程很复杂或在调用 maven-war-plugin 之前做了一些奇怪的事情,这可能不适合您。

第二种选择:如果您运行的是 Linux,请设置 rsync 以将最近修改的文件复制到您的 servlet 容器。一位同事通过让 servlet 容器的 web 应用程序目录与 Eclipse 项目的输出目录同步来做到这一点,并且效果很好(只需修改您的代码,Eclipse 将自动构建它,而 rsync 将复制您的更改)。

于 2011-05-24T04:19:31.553 回答
0

为此,我使用 maven-antrun-plugin

例子:

<project xmlns="http://maven.apache.org/POM/4.0.0" 
....
....
    <!--DJ: Settings for deploy only-->
    <!--DJ: Dir to where copy files-->
    <!--DJ: And date when build have been started, to select only modified files in the future-->
    <properties>
        <tomcat.dir.rootDir>C:\apache-tomcat-6.0.35\webapps\ROOT1</tomcat.dir.rootDir>
        <maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
    </properties>
 .....
<!--Ohter dependensies here-->
 .....
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copyModifiedFilesFrom_ExplodedWAR_Dir</id>
                        <phase>install</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <echo message="Upload new files to dir ${tomcat.dir.rootDir} modified after date ${maven.build.timestamp} "/>
                                <copy todir="${tomcat.dir.rootDir}">
                                    <fileset dir="${project.build.directory}/${project.build.finalName}" includes="**/*">
                                        <!-- Include only recompiled files -->
                                        <date datetime="${maven.build.timestamp}" pattern="yyyy-MM-dd HH:mm:ss" when="after"/>
                                        <!-- and only *.class files -->
                                        <filename name="**/*.class"/>
                                    </fileset>
                                </copy>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
.....
.....
        </plugins>
    </build>
</project>

然后使用参数运行 maven: mvn pom.xml compile install org.apache.maven.plugins:maven-war-plugin:2.1-alpha-1:exploded

结果,只有更改的文件将被重新编译,并且只有重新编译的文件将在 tomcat webapp 目录中被替换。

于 2012-12-14T12:09:42.557 回答