我用它来构建我的 spring mvc 应用程序:
mvn clean package
我使用 maven war 插件创建一个 war 文件,但我面临的问题是,在我的资源文件夹中,我有 log4j 等的 .properties 文件的开发版本。
当我推送到生产环境并运行时:
java -jar ...
它分解了 war 文件,然后我可以使用我的生产设置修改 .properties 文件,但我显然想在我的 Maven 生产构建过程中执行此操作。
有没有办法告诉maven这是一个生产版本,所以从其他地方获取这些文件?在开发过程中,继续做现在正在做的事情吗?
最佳答案
用户 Maven 配置文件。 Maven 配置文件可帮助您为不同的配置文件指定不同的属性。因此,您可以拥有两个配置文件 - 开发和生产。
类似这样的东西 -
<profiles>
<profile>
<id>development</id>
<!-- we'll properties here... -->
</profile>
<profile>
<id>production</id>
<!-- ...and here -->
</profile>
</profiles>
喜欢这个例子 -
<profile>
<id>development</id>
<properties>
<db.driverClass>oracle.jdbc.driver.OracleDriver</db.driverClass>
<db.connectionURL>jdbc:oracle:thin:@127.0.0.1:1521:XE</db.connectionURL>
</properties>
</profile>
<profile>
<id>production</id>
<properties>
<db.driverClass>oracle.jdbc.driver.OracleDriver</db.driverClass>
<db.connectionURL>jdbc:oracle:thin:@134.0.0.1:3124:XE</db.connectionURL>
</properties>
</profile>
关于java - 使用maven创建.war文件,如何使用我的生产资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16132184/