Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the module name from pom in java

Tags:

java

maven

I have a requirement in which based on module names, I need to do some operations. How to fetch the modules name from pom.xml in a java class. My pom.xml has like below :

<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>


<modules>
        <module>name1</module>
        <module>name2</module>    
</modules>

I saw we can get artifactId and version as below from a property file. Here module is a list how to get the modules names from the list. Any help would be appreciated.

version=${project.version}
artifactId=${project.artifactId}

Thanks

like image 618
Vinod Sidiginamale Avatar asked Aug 03 '17 13:08

Vinod Sidiginamale


People also ask

What is module in POM?

A multi-module project is built from an aggregator POM that manages a group of submodules. In most cases, the aggregator is located in the project's root directory and must have packaging of type pom. The submodules are regular Maven projects, and they can be built separately or through the aggregator POM.

What is name in POM xml?

POM is an acronym for Project Object Model. The pom. xml file contains information of project and configuration information for the maven to build the project such as dependencies, build directory, source directory, test source directory, plugin, goals etc.

What is artifactId in POM file?

artifactId is the name of the jar without version. If you created it, then you can choose whatever name you want with lowercase letters and no strange symbols. If it's a third party jar, you have to take the name of the jar as it's distributed.

What is module in Maven project?

A Maven module is a sub-project. To create a Maven module you will need to already have a Maven project available. The parent project must have its Packaging option pre-configured to pom, for a module to be created and associated with it.


1 Answers

You could

  • Define the names as Maven properties.
  • Define a text file in resources which uses these properties.
  • Process this resource file with Maven.
  • Read from the resource file in your jar/war.
like image 132
J Fabian Meier Avatar answered Oct 28 '22 19:10

J Fabian Meier