【问题标题】:Java multi-Module (jar dependecies) with only one property file只有一个属性文件的 Java 多模块(jar 依赖项)
【发布时间】:2018-12-19 16:50:31
【问题描述】:

我的 spring java proyect 带有几个多模块,这些模块将被编译为 jar 文件,这些文件将包含在主模块中。

|-- 模块1 |-- 模块2 |-- 模块3 . . |-- 主模块

模块 1、2 和 3 将被编译为包含在 Main 模块中的 jar 文件。 关键是在每个模块中都有一个“application.property”文件来使用@Value 注释。 关键是我希望只有一个“application.properties”文件包含模块的所有属性来集中这些属性,而不必打开每个属性文件来更改它们。

这可能吗?我该怎么做?

提前致谢

【问题讨论】:

  • 你应该编写一个 maven 或 ant 任务,将所有 application.properties 连接到主模块中

标签: java spring web-applications properties


【解决方案1】:

您可以使用maven-antrun-plugin 运行ant concat task。像下面这样的东西应该可以工作。

<plugin> 
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
        <phase>prepare-package</phase>
        <configuration>
            <target>
                <concat destfile="${project.build.directory}/application.properties">
                    <fileset file="${project.basedir}/../module1/src/main/resources/application.properties" />
                    <fileset file="${project.basedir}/../module2/src/main/resources/application.properties" />
                    <fileset file="${project.basedir}/../module3/src/main/resources/application.properties" />
                </concat>
            </target>

        </configuration>
        <goals>
            <goal>run</goal>
        </goals>
      </execution>
    </executions>
</plugin>

【讨论】:

  • 很抱歉没有回答你,但它工作得很好,谢谢!
猜你喜欢
  • 2018-01-04
  • 1970-01-01
  • 1970-01-01
  • 2018-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-23
相关资源
最近更新 更多