【问题标题】:Dealing with per-developer resources such as database.properties or log4j.properties in a java project在 Java 项目中处理每个开发人员的资源,例如 database.properties 或 log4j.properties
【发布时间】:2012-08-21 08:42:23
【问题描述】:

我们是 4 名开发人员,致力于一个基于 maven 的 java web 项目。我们每个人都有一个特定的 database.properties 文件,该文件指向每个开发人员的数据库架构。

我们目前遇到的问题是,我们有时会无意中提交我们的 per-developper database.properties 或 log4j.properties 文件,这会导致明显的问题。

另一方面,如果我们将这些文件放到 Tomcat 的 /lib 目录中,我们可能会忘记将它们包含到交付的生产应用程序中。

任何人都可以提供建议或建议最佳做法以解决此问题吗?

【问题讨论】:

标签: java maven resources log4j


【解决方案1】:

您应该开始同时使用Maven ProfilesMaven Resource Filtering

如果您将这两种技术结合起来,那么每个用户都可以在%USER_HOME%/.m2/settings.xml 文件中定义他的个人资料,而database.propertieslog4j.properties 文件使用资源过滤从用户个人资料属性中获取用户特定的属性。

我一直在使用这种技术通过设置如下结构来支持不同的数据库:

src
  |-main
       |-filters
       |       |-derby.properties
       |       |-h2.properties
       |       |-mssql.properties
       |       |-mysql.properties
       |-templates
                 |-db.properties

在我的pom.xml

<profiles>
    <profile>
        <id>derby</id>
        <build>
            <filters>
                <filter>src/main/filters/derby.properties</filter>
            </filters>
            <resources>
                <resource>
                    <directory>src/main/templates</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
        </build>
    </profile>
    <profile>
        <id>mysql</id>
        <build>
            <filters>
                <filter>src/main/filters/mysql.properties</filter>
            </filters>
            <resources>
                <resource>
                    <directory>src/main/templates</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
        </build>
    </profile>
    <profile>
        <id>mssql</id>
        <build>
            <filters>
                <filter>src/main/filters/mssql.properties</filter>
            </filters>
            <resources>
                <resource>
                    <directory>src/main/templates</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
        </build>
    </profile>
    <profile>
        <id>h2</id>
        <build>
            <filters>
                <filter>src/main/filters/h2.properties</filter>
            </filters>
            <resources>
                <resource>
                    <directory>src/main/templates</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
        </build>
    </profile>
</profiles>

你应该能够对你的文件做同样的事情。

【讨论】:

    【解决方案2】:

    使用 Git 并仅在您 clense 本地引用时推送到 master。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-09
      • 1970-01-01
      • 2014-06-17
      • 2012-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多