0%

maven资源管理

maven资源管理

配置文件

在maven中可以将配置文件中引用的maven中的属性值进行属性过滤,替换属性值
<build>中添加<resources>进行属性文件过滤,替换属性值
resources中定义那些目录下的文件会被配置文件中定义的变量替换

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<resources>
<resource>
<!-- 编译之后文件移动到的位置 -->
<targetPath></targetPath>
<!-- 属性文件所在目录,表示src/main/resources下的所有properties文件中的变量都会替换 -->
<directory>
src/main/resources
</directory>
<!-- 如果filtering是false表示不会进行替换 -->
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
<resources>

web资源过滤

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>

<configuration>
<webResources>
<resource>
<filtering>true</filtering>
<directory>${project.basedir}/src/main/WebContent/WEB-INF
</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<targetPath>WEB-INF</targetPath>
</resource>
<resource>
<filtering>true</filtering>
<directory>${project.basedir}/src/main/WebContent/WEB-INF/jsp
</directory>
<targetPath>WEB-INF/jsp</targetPath>
</resource>

<resource>
<filtering>true</filtering>
<directory>${project.basedir}/src/main/WebContent/WEB-INF/css
</directory>
<targetPath>WEB-INF/css</targetPath>
</resource>


<resource>
<filtering>true</filtering>
<directory>${project.basedir}/src/main/WebContent/WEB-INF/js
</directory>
<targetPath>WEB-INF/js</targetPath>
</resource>
<resource>
<filtering>true</filtering>
<directory>${project.basedir}/src/main/WebContent/WEB-INF/images
</directory>
<targetPath>WEB-INF/images</targetPath>
</resource>
<resource>
<filtering>true</filtering>
<directory>${project.basedir}/src/main/WebContent/WEB-INF
</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<targetPath>WEB-INF</targetPath>
</resource>
</webResources>
</configuration>

</plugin>

欢迎关注我的其它发布渠道