maven-war-plugin根据环境打包资源

声明:本文参考资料来自互联网


J2EE项目在开发时,需要根据不同环境适配资源文件,maven提供了war-plugin这款打包插件,方便完成这个适配。


首先配置maven profile,再次不再详述,参见官方文档。demo中,prod的资源依旧放在src/main/resources中,dev、qa资源置于src目录外。可根据实际情况调整。

<profiles>
		<!-- dev配置 -->
		<profile>
			<id>dev</id>
			<activation>
        		<activeByDefault>true</activeByDefault>
    		</activation>
			<properties>
				<runtime.env>env/dev</runtime.env>
				<final.name>filename</final.name>
			</properties>
		</profile>
		<!-- qa配置 -->
		<profile>
			<id>qa</id>
			<properties>
				<runtime.env>env/qa</runtime.env>
				<final.name>filename</final.name>
			</properties>
		</profile>
		<!-- prod配置 -->
		<profile>
			<id>prod</id>
			<properties>
				<runtime.env>src/main/resources</runtime.env>
				<final.name>filename</final.name>
			</properties>
		</profile>
	</profiles>

然后引入maven-war-plugin插件

<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>3.0.0</version>
				<configuration>
					<webResources>
						<resource>
							<directory>${runtime.env}</directory>
							<targetPath>WEB-INF/classes</targetPath>
						</resource>
					</webResources>
					<warSourceExcludes>resources/js/**</warSourceExcludes>
				</configuration>
			</plugin>



warSourceExcludes 可以过滤掉不需要打包的资源文件


--- 20161220 补充 yuicompressor-maven-plugin 插件,打包js,css成min文件 ---

<plugin>
				<groupId>net.alchim31.maven</groupId>
				<artifactId>yuicompressor-maven-plugin</artifactId>
				<version>1.3.0</version>
				<executions>
                    <execution>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>compress</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                	<encoding>UTF-8</encoding>
                	<jswarn>false</jswarn>
                	<force>false</force>
                	<suffix>.min</suffix>
                	
                	<excludes>
                        <exclude>**/*.min.js</exclude>
                        <exclude>**/*.min.css</exclude>
                        <exclude>resources/component/**</exclude>
                        <exclude>resources/image/**</exclude>
                    </excludes>
                    
                    <includes>  
                		<include>**/*.js</include>  
                		<include>**/*.css</include>  
            		</includes>
                </configuration>
			</plugin>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值