只复制maven-war-plugin中修改过的文件

发布于 2024-10-29 08:28:33 字数 215 浏览 4 评论 0原文

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

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

谢谢。

I'm currently using maven 3.x with the maven-war-plugin. For developer builds I would like to be able to use the war:exploaded goal, but only copy resources that have changed. Is there a way to do this?

I've been looking through the docs and have not been able to find a way to do this in the current versions, but there used to be (in the old maven 1.x version) a property maven.war.resources.overwrite that would allow this.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紅太極 2024-11-05 08:28:33

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

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

I'm not aware of a way to do this using the maven-war-plugin, but if your IDE supports it, you could have the IDE auto-deploy changes. For example, the Web Tools Platform for Eclipse supports this feature for Tomcat. However, if your build process is complex or does something weird before invoking the maven-war-plugin, this may not work for you.

A second option: if you're running Linux, set up rsync to copy recently modified files to your servlet container. A co-worker did this by having the servlet container's web app directory sync with the Eclipse project's output directory, and it worked well (just modify your code, Eclipse will build it automatically, and rsync will copy your changes).

浮生面具三千个 2024-11-05 08:28:33

为此,我使用 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 目录中被替换。

For this purpose I use maven-antrun-plugin

Example:

<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>

Then run maven with params:
mvn pom.xml compile install org.apache.maven.plugins:maven-war-plugin:2.1-alpha-1:exploded

As result only changed files will be recompiled and only recompiled filed will be replaced in tomcat webapp dir.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文