【问题标题】:Maven Resources Plugin: how to copy resources to target folder and keep time stamps?Maven Resources Plugin:如何将资源复制到目标文件夹并保留时间戳?
【发布时间】:2013-01-24 14:17:50
【问题描述】:

当我在项目上执行清理和构建时,Maven 将所有资源复制到目标文件夹,但带有创建的时间戳,而不是 src/main/resources 文件夹中原始文件的时间戳。是否有可能以某种方式指示它保留原始时间戳?

这对我们来说有问题的原因是我们正在开发的软件在启动时有一个数据库迁移,我们希望让它在开发人员机器上执行。但由于时间戳不断变化,这会导致数据库不必要的资源重新加载。

【问题讨论】:

标签: java maven


【解决方案1】:

我认为不可能使用Maven resources plugin 的默认功能。

您能否更改运行时加载文件的路径(可能通过使其可根据环境进行配置)?如果是这样,那么也许您可以使用 ant with maven 并使用具有 preservelastmodified 属性的 ant's copy task

其意图是 Maven 的资源处理将继续照常工作,但文件也会在每次构建时复制到运行时使用的单独位置。

【讨论】:

    【解决方案2】:

    解决方法是使用ant的copy任务。 这分两步完成: 1)从正常处理中排除我们想要保留日期的文件(在这个例子中,我处理测试资源。这同样适用于构建资源):

    <testResources>
        <testResource>
            <directory>src/test/resources</directory>
            <excludes>
                <exclude>**/some-files*/**</exclude>
            </excludes>
        </testResource>
    </testResources>
    

    2)第二步是使用mave ant插件将它们复制到ant task中:

    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <executions>
            <execution>
                <phase>process-test-resources</phase>
                <configuration>
                    <tasks>
                        <copy todir="${project.build.testOutputDirectory}" preservelastmodified="true">
                            <fileset dir="src/test/resources">
                                <include name="**/some-file*/**"/>
                            </fileset>
                        </copy>                            
                    </tasks>
                </configuration>
                <goals>
                    <goal>run</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    【讨论】:

    • 我刚刚添加了 overwrite="true" 到蚂蚁,这使得排除不必要
    猜你喜欢
    • 2014-10-14
    • 2012-06-11
    • 1970-01-01
    • 2018-03-05
    • 1970-01-01
    • 2013-11-20
    • 2017-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多