• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand what you want to do. What package do you depend on?
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you maybe give us an SSCCE?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic