java项目中index页的动态替换(maven-war-plugin)

原理类似于第三种配置方法:动态配置index中静态文件路径

利用maven占位符进行动态更换配置内容,实现index页面的动态替换(在打包时根据不同的部署环境,生成不同的web.xml文件):

1.在pom文件配置插件:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webResources>
                        <resource>
                            <filtering>true</filtering>
                            <directory>src/main/webapp</directory>
                            <includes>
                                <include>index.html</include>
                            </includes>
                            <includes>
                                <include>**/web.xml</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>

2.在pom文件不同的部署环境配置占位符内容:

<profiles>
        <profile>
            <id>local</id>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/profiles/local</directory>
                    </resource>
                </resources>
            </build>
            <properties>
                <profile.env>local</profile.env>
                <log.root.level>INFO</log.root.level>
                <log.logger.level>DEBUG</log.logger.level>
                <log.console.level>INFO</log.console.level>
                
                
                 <!--index文件名,占位符内容-->
                <index.file>index.html</index.file>
            </properties>
        </profile>
        <profile>
            <id>development</id>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/profiles/development</directory>
                    </resource>
                </resources>
            </build>
            <properties>
                <profile.env>development</profile.env>
                <log.root.level>INFO</log.root.level>
                <log.logger.level>DEBUG</log.logger.level>
                <log.console.level>INFO</log.console.level>
  

                
                 <!--index文件名,占位符内容,与local环境不同-->
                <index.file>demo.html</index.file>
            </properties>
        </profile>
</profiles>

3.在web.xml中进行配置占位符:

<welcome-file-list>
        <welcome-file>${index.file}</welcome-file>
</welcome-file-list>

4.选择install环境:

 这样生成的target就会生成web.xml:

web.xml文件就会会被替换:

local

 development

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值