Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import from other module

Tags:

I write project using Java and Maven. In project I have many modules. My problem is that I can not import classes from other module.

My project structure looks like this:

Project  |_ module1     |_ src        |_ com.xyz.project.md1           |_ Person.java     |_ pom.xml <- pom of module1  |_ module2     |_ src        |_ com.xyz.project.md2           |_ Robot.java     |_ pom.xml <- pom of module2  |_ pom.xml <- main Project pom 

module1 and module2 are Modules in my project, which are registred in pom.xml - main Project pom

And when I am in Person.java from module1 I want import the Robot.java from module2 but I can not do this with import com.xyz.project.md2.Robot. Why ?

like image 265
CeZet Avatar asked Apr 28 '16 13:04

CeZet


People also ask

Can you import a module into a module?

Such a file is called a module; definitions from a module can be imported into other modules or into the main module (the collection of variables that you have access to in a script executed at the top level and in calculator mode).

Can you import a module into a module in Python?

The import statement allows you to import one or more modules into your Python program, letting you make use of the definitions constructed in those modules.


1 Answers

Declare dependency to module2 in module1/pom.xml, something like this:

<dependencies>     ...             <dependency>                 <groupId>XX</groupId>                 <artifactId>module2</artifactId>                 <version>0.0.1-SNAPSHOT</version>             </dependency>     ... </dependencies> 
like image 75
Y.E. Avatar answered Oct 04 '22 00:10

Y.E.