How to add a project to another project?

There are two independent projects ( myWarProject and MyEjbProject ). Therefore, when I create myWarProject , I need to install MyEjbProject in the local repository, so I can define myWarProject as a dependency and successfully package myWarProject.

Is there a way to handle this without installing MyEjbProject separately, and also without specifying as parent modules.

I know this can be achieved with the ant build, but wonder if there is a way to manage through maven?

We can create a parent project using "pom" and move the other two under the parent project. However, unfortunately, I cannot do this, because currently we already have these two separate projects in CVS, which I cannot change the structure of. If I can handle this through a pom file, this is what I am looking for.

+44
maven-3
Mar 13 '13 at 10:56
source share
1 answer

Assuming MyEjbProject is not another Maven project that you have or want to build using maven, you can use system dependencies to bind to an existing project jar file, for example

 <project> ... <dependencies> <dependency> <groupId>yourgroup</groupId> <artifactId>myejbproject</artifactId> <version>2.0</version> <scope>system</scope> <systemPath>path/to/myejbproject.jar</systemPath> </dependency> </dependencies> ... </project> 

However, as a rule, it is better (and preferred) to install the package in the repository either by creating a maven project, either creating it, or installing it, as you already seem to be doing.

EDIT: If they are, however, dependent on each other, you can always create a separate parent project (should be a β€œpom” project) by declaring the other two projects as your β€œmodules”. (Subsidiary projects should not have announced the third project as their parent). As a result, you will get a new directory for the new parent project, where you would probably also place two independent projects as follows:

 parent |- pom.xml |- MyEJBProject | `- pom.xml `- MyWarProject `- pom.xml 

The parent project will receive the "modules" section to name all the child modules. Then the aggregator will use the dependencies in the child modules to actually determine the order in which the projects should be created)

 <project> ... <artifactId>myparentproject</artifactId> <groupId>...</groupId> <version>...</version> <packaging>pom</packaging> ... <modules> <module>MyEJBModule</module> <module>MyWarModule</module> </modules> ... </project> 

Thus, projects can relate to each other, but (as soon as they are installed in the local repository) are still used independently as artifacts in other projects

EDIT2:

Finally, if your projects are not related to related directories, you can try to provide them as relative modules:

 filesystem |- mywarproject | `pom.xml |- myejbproject | `pom.xml `- parent `pom.xml 

now you could just do it (worked in maven 2, just tried):

 <!--parent--> <project> <modules> <module>../mywarproject</module> <module>../myejbproject</module> </modules> </project> 
+33
Mar 13 '13 at 11:08
source share



All Articles