Reputation: 35
I have a multi-module maven project ,where the modules call java classes.I want to store a variable and access it from other module.Can it be done using MavenProject? if yes how can I use it
Upvotes: 0
Views: 604
Reputation: 552
If you are referring to sharing variables across pom.xml, You can set the variables in the tag in the parent pom.xml and reference it from other modules.
something like
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.version>0.0.1-SNAPSHOT</project.version>
</properties>
and refer in the modules as ${project.version}
Upvotes: 1
Reputation: 41
When I had the same issue, I installed one module as a jar inside the other one.
Let's say I have a module A, and the Module B wants to access runtime variables in module B.
In module A I would put this line in the pom.xml
<packaging>jar</packaging>
In module B I would import module A as a dependency
<dependency>
<groupId>com.my.module.A</groupId>
<artifactId>my-module-A</artifactId>
<version>modueAversion</version>
</dependency>
Then I would run a maven install in module B, which installs the module B in my repository.
After that update the dependencies in project A. In the maven dependencies section you should see an entry such as "moduleA.jar".
In this way, you can access all the runtime variables, classes, and methods of module A from module B.
I don't know if this is what you needed. I hope to have been of some help
Upvotes: 0