java - 使用maven创建.war文件,如何使用我的生产资源?

标签 java spring maven spring-mvc

我用它来构建我的 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/

相关文章:

java - 如何让maven使用测试资源

java - 掷骰子游戏问题

java - 为 Android 上的 SSH 登录生成 RSA 私钥/公钥对

javascript - 如何让javascript只接受给定的正则表达式?

spring - Angular5 - 设置从 spring 表单登录返回的 cookie

maven - 将docker目录作为Maven参数传递

java - 子模块 Maven 依赖关系管理的最佳实践

java - 在 Pentaho BiServer 中找不到错误 404 pivot4j 文件

java - 如何在hibernate中使用命名查询访问子表字段

java - Spring 安全: deserialize request body twice (oauth2 processing)