爱玩科技网
您的当前位置:首页maven-resources-plugin使用

maven-resources-plugin使用

来源:爱玩科技网
maven-resources-plugin使⽤

命令⾏中带参数指定${}变量值

src/main/resources true

org.apache.maven.plugins maven-resources-plugin 3.0.1

UTF-8

pdf swf

Hello ${name}jest.urls=${name}

(1) 执⾏mvn resources:resources -Dname=\"world\"è

Hello worldjest.urls=world

(2) 执⾏mvn install -Dname=\"world\"è

Hello worldjest.urls=world

Properties标签中指定${}变量值

my testname

src/main/resources true

org.apache.maven.plugins maven-resources-plugin 3.0.1

UTF-8

pdf swf

(1) 执⾏mvn resources:resourcesè

Hello my test namejest.urls=my testname

(2) 执⾏mvn installè

Hello my test namejest.urls=my testname

properties⽂件中⽤标签过滤

src/main/resources true

src/main/resources/my-filter-values.properties

org.apache.maven.plugins maven-resources-plugin 3.0.1

UTF-8

pdf swf

my-filter-values.properties

name=mytestingname

(1) 执⾏mvn resources:resourcesè

Hello my testingnamejest.urls=my testingname

(2) 执⾏mvn installè

Hello my testingnamejest.urls=my testingname

使⽤copy-resources copy

maven-resources-plugin 3.1.0

copy-resources validate

copy-resources

${basedir}/target/extra-resources

src/main/resources true

(1) 执⾏mvn resources:resourcesè

Hello my testingnamejest.urls=my testingname

排除⽂件

...

MyResources Plugin Practice Project ... ...

src/my-resources

**/*.txt

**/*test*.* ...

... ...

排除⼆进制⽂件

...

org.apache.maven.plugins maven-resources-plugin 3.1.0 ...

pdf swf ...

... ...

禁⽌过滤 使⽤

my test name

src/main/resources true

org.apache.maven.plugins maven-resources-plugin 3.0.1

\\

指定\\, 说明\\${}的è${},其它照样替换

Hello\\${name}jest.urls=${name}

(1) 执⾏mvn resources:resourcesè

Hello ${name}jest.urls=my testname

(2) 执⾏mvn installè

Hello ${name}jest.urls=my testname

根据id在不同环境下打对应参数

src/main/resources true

org.apache.maven.plugins maven-resources-plugin 3.0.1

\\

dev

http://n2:9200,http://n4:9200

true

production

http://192.168.3.241:9200,http://192.168.3.242:9200

mvn clean package-DskipTests -Pdevè

Hello\\${jest.urls}

jest.urls=http://n2:9200,http://n4:9200

mvn clean package-DskipTests -Pproductionè

Hello\\${jest.urls}

jest.urls=http://192.168.3.241:9200,http://192.168.3.242:9200

⾃定义过滤器 Custom resources filters

With version 2.5 you are now able to build your own customresources filter(s).Your custom resources filter classes must implements .CustomResources Filter Implementation

Your custom resources filter classes must be marked as aPlexus Component. Below a sample with a roleHint itFilter.

1. /**

2. * @plexus.component role=\"org.apache.maven.shared.filtering.MavenResourcesFiltering\" 3. * role-hint=\"itFilter\"4. */

5. public class ItFilter

6. implements MavenResourcesFiltering

Then you must activate in your build the mojo which willscan javadoc annotations to transform thoses to plexus component metadata.

1.

2. org.codehaus.plexus3. plexus-maven-plugin4. 1.3.45. 6. 7.

8. descriptor9. 10. 11. 12.

Dependencydeclaration

Your classes must be available in the maven-resources-pluginclasspath, this can be done with adding your artifact to theplugindependencies.

1. 2. ...3. 4. 5.

6. org.apache.maven.plugins7. maven-resources-plugin8. 3.1.09. 10. ...

11. 12. 13.

14. custom resources filters artifact groupId15. custom resources filters artifact artifactId16. custom resources filters artifact version17. 18.

19. 20. 21. ...22. 23. ...24.

Useof your Custom Resource Filter with the maven-resources-plugin

You must now declare you custom filter in the plugin.mavenFilteringHint must respect same syntax as your Plexus Component roleHint.

1.

2. org.apache.maven.plugins3. maven-resources-plugin4. 3.1.05. 6. ...

7.

8. itFilter9. 10. 11. ...

12. 13.

因篇幅问题不能全部显示,请点此查看更多更全内容