This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes copy maven module of one maven git repository to another maven git repository Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "copy maven module of one maven git repository to another maven git repository" Watch "copy maven module of one maven git repository to another maven git repository" New topic
Author

copy maven module of one maven git repository to another maven git repository

Amy Aim
Greenhorn

Joined: Aug 08, 2013
Posts: 6
hi

I am new to maven.
I want to reuse a maven module which is part of a maven git project in another maven git project.
I know how to create a maven module in a maven project but no idea about the best way to copy a maven module from project-1 to project-2(through command line or any ide)

appreciate your inputs

thanks a lot!
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3575
    
  14

Clone the git repository of project-1, and install it (mvn install). From project-2, declare a dependency on project-1. Whenever you need to update project-1, pull from the upstream and re-install.
Amy Aim
Greenhorn

Joined: Aug 08, 2013
Posts: 6
Thanks Stephen.

Can you tell me a way to clean copy without adding dependency on project-1. As the main focus is to copy the structure and few class files and need not keep this copied module up to date with the module in project-1
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3575
    
  14

If I'm understanding you correctly, you want to use code from an existing maven sub-module in your new project?

Then why don't you just clone the repository, and simply copy the required classes and paste them into the src folder of your own project?

Note that you may not be allowed to do everything I described here. Pay attention to project-1's license.

All of this should only really be useful if you plan to change the original code to fit your own needs. If you just need to interact with the classes, a dependency really is the best option. Maybe you can tell us more of your plans?
Amy Aim
Greenhorn

Joined: Aug 08, 2013
Posts: 6
Thanks Stephan.
Yeah started with copying exsiting project and I started reusing some classes which I can and removed the rest.

But now I realise adding dependency of the packages I need to reuse is a reliable solution.

I have browsed through for steps to creating jar of a package and then adding this as dependency in pom of a project.

Could you please help me with the steps to the above

Thanks
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3575
    
  14

I don't understand what you want to do. What package do you depend on?
Sindhuri krish
Greenhorn

Joined: Jun 11, 2013
Posts: 17
Hi Stephen

I meant java package which the classes belong to. I am thinking to add only packages(from the existing repository) which have classes that could be reused in the new project.

So should I create jar of each java package and add this package as dependency in pom file of new project? Please help me with the steps
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3575
    
  14

If you're not planning on changing the code in the package, I would advise to put a dependency directly on the third party maven project. There's really not much point in creating your own maven project using a subset of the available code.

If you are hell-bent on using a local subset, then create a new maven project, and simply move the packages that you need to your project's src/main/java folder. Then install and place a dependency on that project. You don't need to create jars yourself.
Sindhuri krish
Greenhorn

Joined: Jun 11, 2013
Posts: 17
Thanks Stephen.

I have added the project as dependency in pom but as we are using spring , many beans in the existing project are not getting identified in the local project in runtime.

So in spring context.xml , I have tried adding the base package of the existing project in context:component-scan base-package= newprojectpackagepath,exisitingprojectpath

But I get many errors related to 'Injection of autowired dependencies failed'

Is it okay to add another repo(which is added as maven dependency) package path in springcontext of a project?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3575
    
  14

Can you maybe give us an SSCCE?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: copy maven module of one maven git repository to another maven git repository
 
Similar Threads
The POM for org.eclipse.persistence:eclipselink:jar:2.3.0 is missing
Java and github
Maven Repository
Maven: What's the big deal?
How to use GIT with eclipse