I want to use maven project 2 classes in my maven project 1 so that I can use it as a parent class. Can you please tell me how to do this using eclipse and JAVA. Please write in step by step navigation as I am new in maven.
Thanks in advance
I want to use maven project 2 classes in my maven project 1 so that I can use it as a parent class. Can you please tell me how to do this using eclipse and JAVA. Please write in step by step navigation as I am new in maven.
Thanks in advance
I know its too late But this could help others who are searching for same problem.
suppose you have 2 projects p1 and p2 and you want to use p2 project's classes in p1 project then,
A) Right Click on your p2 maven project(If not maven project then convert it to maven) then
-->Choose Run As-->Click on Maven Install.
(It will make p2 to avaliable for other projects in your local maven repository)
B) Now you can simply add p2 project as dependency in p1 project's pom.xml file like this
<dependency>
<groupId>com.project.p2</groupId>
<artifactId>p2</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
For more details see this
maven install is a hack. the correct thing to do is create an aggregator pom that includes both project directories something like this:
<packaging>pom</packaging>
<modules>
<module>pathTo/P1</module>
<module>pathTo/P2</module>
</modules>
and then from this new pom directory run
mvn -am compile
the "-am" here is what is important. It will ensure both projects are added to the reactor and are discoverable.
Import this new project into eclipse and everything will work as expected.
You can add your local project 1 what is in yor eclipse workspace to your local maven repository.
With this command (command line) yor are able to build this project to a pom.
mvn install:install-file -Dfile=c:\whereYoureFileIs-{version}.jar -DgroupId=com.companyName.projectName
-DartifactId=projectName -Dversion={Your version} -Dpackaging=jar
and after you build your jar of Project 1 to your local maven repository you are able to use this jar in your second project as a dependency. After including this jar you can extend the class you need.
If you need more explanation, please let me know.
add a maven dependency like this :
<dependency>
<groupId>groupId of project2</groupId>
<artifactId>artifactId of project2</artifactId>
<version>version of project2</version>
</dependency>
First Create parent java project Simple java project
Click on project (right-click) -> Configure -> Convert to maven project
Convert to Maven Convert Java to Maven
Right click on parent project -> new -> Porject... select maven module
Create another Maven Module child project depend on base project ex : called (webapp)
Open webapp/pom.xml -> dependencies tap
Click add -> search about your base group id and select -> save