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 - 使用文件服务 URL 从 blobstore 中删除文件

java - 什么时候需要导入 java.awt.*?如果我想导入 javax.swing.* 是否还需要导入 java.awt.*?

spring - 使用 spring boot 托管单页应用程序

maven - 如何使用 maven pom.xml 创建 jar

java - 在 AWS Beanstalk 中运行 WAR 文件

java - Elasticsearch java.lang.NoClassDefFoundError:org/elasticsearch/transport/Netty3Plugin

java - 仅在某些环境中应用 servlet 过滤器

java - Firebase - 如何检索数据库项目的 ID?

java - Spring 中未调用 Rest Controller

spring - Grails 3.x : Re-using JPA/Hibernate Domain classes: Domain class not found