In src > main > java > ... > XXX.java, if import package.module.YYY, mvn compile, then an error of package package.module.YYY doesn't exist:
this is because though import package.module.YYY, the jar that contains class YYY is not added in ClassPath. In maven, an easier solving approach is possible:
- In src directory of
YYY,mvn installto publish jar containingYYYin local repository. - In
pom.xmlofXXX, addYYYas a new dependency:1
2
3
4
5<dependency>
<groupId>package</groupId>
<artifactId>module</artifactId>
<version>0.0.1SNAPSHOT</version>
</dependency>
In this way, import ...YYY is possible.
maven install
When import xxx in java source file, maven would go to pom.xml to find if this package dependency is in local repository. If so, add it into classPath; if not, go to maven central repo to download jar for use. If nothing is found, ERROR.