Maven 2 在Maven中过滤文件名
我希望能够在Maven中过滤文件名和文件内容 下面的代码片段可以对文件内容进行过滤,但我也需要能够重命名文件 使用场景是,我希望我的webapp中的所有静态资源都被编号,这样它们就可以被Amazon的CloudFront视为不同的版本。当然,手动管理数字是不切实际的,所以我希望构建过程能够做到这一点 例如,一个名为Maven 2 在Maven中过滤文件名,maven-2,filter,maven,filtering,war,Maven 2,Filter,Maven,Filtering,War,我希望能够在Maven中过滤文件名和文件内容 下面的代码片段可以对文件内容进行过滤,但我也需要能够重命名文件 使用场景是,我希望我的webapp中的所有静态资源都被编号,这样它们就可以被Amazon的CloudFront视为不同的版本。当然,手动管理数字是不切实际的,所以我希望构建过程能够做到这一点 例如,一个名为 logo_VERSION.jpg 最终会被叫来 logo_254.jpg 如果不编写自定义插件就可以实现这一点,有什么想法吗 org.apache.maven.plugins
logo_VERSION.jpg
最终会被叫来
logo_254.jpg
如果不编写自定义插件就可以实现这一点,有什么想法吗
org.apache.maven.plugins
maven战争插件
/src/main/webapp
真的
...
我使用antrun插件做了类似的事情——有时候你只需要回到ant
pom片段
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>build</id>
<phase>prepare-package</phase>
<configuration>
<tasks>
<property name="project.version" value="${project.version}"/>
<property name="all.environs" value="DEV1,DEV2,DEV3,DEV4,UAT,PROD"/>
<property name="application.environments"
value="${application.environments}" />
<ant antfile="${basedir}/build.xml" target="setup" />
<ant antfile="${basedir}/build.xml" target="build"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
org.apache.maven.plugins
maven antrun插件
建造
准备包装
跑
build.xml
让ant contrib
正如您所知,内置资源筛选对文件内容有效,而不是对文件名有效。要想搞乱文件名,恐怕只有自定义插件才能解决问题,不管你是自己写的还是找到的。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>build</id>
<phase>prepare-package</phase>
<configuration>
<tasks>
<property name="project.version" value="${project.version}"/>
<property name="all.environs" value="DEV1,DEV2,DEV3,DEV4,UAT,PROD"/>
<property name="application.environments"
value="${application.environments}" />
<ant antfile="${basedir}/build.xml" target="setup" />
<ant antfile="${basedir}/build.xml" target="build"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<property name="ant-contrib-jar" value="${user.home}/.ant/lib/ant-contrib-1.0b3.jar"/>
<target name="setup" unless="ant-contrib.present">
<echo>Getting ant-contrib</echo>
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${ant-contrib-jar}"
src="http://nexus.inhouse.com:8081/nexus/content/repositories/central/ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3.jar"/>
</target>
<target name="taskdefs">
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${ant-contrib-jar}"/>
</classpath>
</taskdef>
</target>
<target name="build" depends="taskdefs">
<echo message="basedir: ${basedir}"/>
<echo message="project.version: ${project.version}"/>
<foreach list="${application.environments}" target="jar-resources" param="app.env" trim="true">
<param name="basedir" value="${basedir}" />
<param name="project.version" value="${project.version}" />
</foreach>
</target>
<target name="jar-resources">
<mkdir dir="${basedir}/target/${app.env}"/>
<copy todir="${basedir}/target/${app.env}">
<fileset dir="${basedir}/src/main/resources">
<include name="mail_config.properties"/>
<include name="service.properties"/>
</fileset>
</copy>
<filterset id="applicationFilterSet">
<filtersfile file="${basedir}/src/main/filters/filter-${app.env}.properties"/>
<filter token="PROJECT.VERSION" value="${project.version}"/>
</filterset>
<copy file="${basedir}/src/main/resources/coresystem.properties"
tofile="${basedir}/target/${app.env}/coresystem.properties.${app.env}">
<filterset refid="applicationFilterSet"/>
</copy>
<copy file="${basedir}/src/main/resources/extraProps.properties"
tofile="${basedir}/target/${app.env}/extraProps_${app.env}.properties">
<filterset refid="applicationFilterSet"/>
</copy>
<jar destfile="${basedir}/target/MyApp-env-${project.version}-${app.env}.jar"
basedir="${basedir}/target/${app.env}" />
</target>