java - 如何使用 Maven 构建从属性文件中删除注释?

标签 java maven maven-plugin properties-file

假设我的属性文件中有以下内容

#production db
db.url=com.some.prod.url
db.port=4565

#development db
#db.url=com.some.dev.url
#db.port=4577

构建完成后,我希望我的属性文件清除构建文件中所有注释的属性。所以,最终的结果就变成了:

db.url=com.some.prod.url
db.port=4565

最佳答案

终于明白了。 使用过maven-replacer-plugin ,并替换了正则表达式 <new line><hash><any set of characters>\r\n#(.*)<blank>

更新:为了能够在 jenkins(linux 实例,在我的例子中)上执行此操作,添加了一个模式 \n#(.*)

       <plugin>
            <groupId>com.google.code.maven-replacer-plugin</groupId>
            <artifactId>replacer</artifactId>
            <version>1.5.2</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>replace</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <includes>
                    <include>target/**/*.properties</include>
                </includes>
                <commentsEnabled>false</commentsEnabled>
                <regex>true</regex>
                <replacements>
                    <replacement>
                        <token>\r\n#(.*)</token>
                        <value></value>
                    </replacement>
                    <!-- Following line was added in update(linux compatible) -->
                    <replacement>
                        <token>\n#(.*)</token>
                        <value></value>
                    </replacement>
                </replacements>
            </configuration>
        </plugin>

关于java - 如何使用 Maven 构建从属性文件中删除注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53839353/

相关文章:

maven - 使用带有 exec 分类器的 spring-boot-maven-plugin,但无法再从 IDE 运行应用程序

java - 将完整的 Maven 远程存储库下载到本地存储库?

java - 带有用于启动/停止的 Maven 插件的轻量级 Java 数据库?

java - OAuth2RestTemplate 身份验证问题获取 access_denied

java - java 发送和接收二维数组

java - EJB 池与线程安全和@PreDestroy

maven - 在 WAR 中读取文件

java - 如何解决OneSignal错误: "Segment is not a valid filter field"

java - 自动将流量迁移到最新的 Google 应用引擎版本

Eclipse 'refresh automatically' 和 Maven 构建干扰