【问题标题】:read properties of pom.xml of a maven ear/ejb from a jar file which is as a part of maven dependency从 jar 文件中读取 maven ear/ejb 的 pom.xml 的属性,该 jar 文件是 maven 依赖项的一部分
【发布时间】:2016-12-20 11:39:08
【问题描述】:

我有 maven jar 文件,它作为依赖项包含在 maven ejb 中。下面解释所有项目结构:

1) 父级 (reports-service) 的 pom.xml :

    <groupId>com.xxx.pdf.reports</groupId>
    <artifactId>reports-parent</artifactId>
    <version>2.0.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>Reports - Parent</name>
    <modules>
        <module>reports-application</module>
        <module>reports-service</module>
    </modules>

2) pom.xml of ear(reports-application) :
  <parent>
    <groupId>com.xxx.pdf.reports</groupId>
    <artifactId>reports-parent</artifactId>
    <version>2.0.0-SNAPSHOT</version>
  </parent>
  <artifactId>reports-application</artifactId> 
  <packaging>ear</packaging> 
  <dependencies>
        <dependency>
            <groupId>com.xxx.pdf.reports</groupId>
            <artifactId>reports-service</artifactId>
            <version>${project.version}</version>
            <type>ejb</type>
        </dependency>
  </dependencies>

3) pom.xml of ejb(reports-service) :    
    <parent>
        <groupId>com.xxx.pdf.reports</groupId>
        <artifactId>reports-parent</artifactId>
        <version>2.0.0-SNAPSHOT</version>
    </parent>
    <artifactId>reports-service</artifactId>
    <packaging>ejb</packaging>
    <dependencies>
        <dependency>
            <groupId>com.xxx.common.serviceframework</groupId>
            <artifactId>ServiceFramework</artifactId>
            <version>1.1.0-SNAPSHOT</version>
        </dependency>
        .......other dependencies..........
        ................

4) pom.xml of jar(ServiceFramework) :
    <groupId>com.xxx.common.serviceframework</groupId>
    <artifactId>ServiceFramework</artifactId>
    <version>1.0.0-SNAPSHOT</version>

如上所述,reports-service 是构建报表应用程序和报表服务的父 pom。这两者都是它的模块。

reports-application 只是一个包含reports-service(ejb) 的耳朵。

reports-service 包含 ServiceFramework(jar) 作为其依赖项。此 ServiceFramework 包含连接到数据库以保存信息的代码。现在这个 ServiceFramework 可以包含在任何 ebj 中(我的项目中有很多这样的),比如报告服务来保存信息。

现在,我想从 ServiceFramework 中的 java 代码获取报告服务的版本(以及一些其他 pom.xml 信息,如 groupId && artifactId)。我尝试使用 Maven 资源插件。

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
    </resource>
</resources>

但它给了我 ServiceFramework 的版本,因为选择版本的 java 代码在 ServiceFramework jar 中。我想要使​​用 ServiceFramework jar 的应用程序版本。我尝试了所有方法,但所有方法都为我提供了 ServiceFramework 版本。

要求 ServiceFramework 应该能够获取包含它作为其依赖项的 ejb 的 pom 信息。那么,如何从 ServiceFramework 获取/读取报告服务的 pom 信息?

【问题讨论】:

    标签: spring maven maven-plugin


    【解决方案1】:

    我认为您已经很接近解决方案了。您尝试使用filtering 来“捕获”ServiceFramework 中的 groupId & artifactId & version (aka GAV)。相反,在reports-service 中使用filtering,捕获GAV 并写入某个资源文件,比如说x.properties

    您位于 ServiceFramework 中的 java 代码应该从类路径加载资源 x.properties 并读取您想要的所有内容

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-21
      相关资源
      最近更新 更多