Question

I'm a Java developer using Eclipse and Maven. There are some modules I created in a project that I'd like to reuse in my future projects. Is there any standard way to accomplish this using Maven?

I don't like the idea of including classpath in other project. I'm looking for a way to publish and share some specific packages using Maven and over the time I should have a consistent Java library for myself.

Was it helpful?

Solution 2

This is a very common usecase and nicely covered as maven multimodule project. Check the link for a simple example http://docs.codehaus.org/display/MAVENUSER/Multi-modules+projects. For local development it's enough to run mvn install. In a bigger project or shared environment you will need a maven repository.

Update:

Alternative link: Multi-module project builds with Maven and Gradle

OTHER TIPS

You can publish those already existing jars in your repo using mvn clean package install and then add those as a dependency to your pom file in the new projects, whereever you chose to use them

If you want to reuse some code, then you would have to make a new artifact and add this one as a dependency to your over deliverables. As mentioned by tigran this could be nicely done by using maven multi modules architecture but you can just create a new deliverable used other several projects.

If you can build a jar for the classes you want to reuse, you can deploy them to a Maven repository for future reuse by other projects. However, based on the comments I read so far, you want something like source code level sharing. I assume you use Windows platform for your development. You can use junction or symbolic link to link at the source code level between different projects. Also most of modern version control system like Accurev/Clearcase have support for symbolic link.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top