1
votes

I have maven jar file which is included as dependency in a maven ejb. Explaining below all project structure :

1) pom.xml of parent(reports-service) :

    <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>

As mentioned above, reports-service is the parent pom which builds reports-application and reports-service. This both are its modules.

reports-application is just an ear which includes reports-service(ejb).

reports-service contains ServiceFramework(jar) as its dependency. This ServiceFramework contains code which connects to database to save informations. Now this ServiceFramework can be included by any ebj's(there are many such in my project) like reports-service to save information.

Now, i want to get the version(and some other pom.xml informations like groupId && artifactId) of reports-service from java code in ServiceFramework. I tried using maven resources plugin.

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

But it gives me version of ServiceFramework since the java code to pick the version is in ServiceFramework jar. I want the version of the application which is using the ServiceFramework jar. I tried everything but all approach gives me version of ServiceFramework.

The requirement is such that ServiceFramework should be able to get pom information of the ejb which has included it as its dependency. So, how can i get/read the pom information of reports-service from ServiceFramework ?

1

1 Answers

1
votes

I think you are quite near a solution. You tried to use filtering to "catch" groupId & artifactId & version (aka GAV) in ServiceFramework. Instead, use filtering in reports-service, catch GAV and write to some resource file, let say x.properties.

Your java code located in ServiceFramework should load resource x.properties from classpath and read all you want