You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Nishant Neeraj <nn...@yahoo.com> on 2010/01/21 10:19:25 UTC

Sharing Module among Multiple Projects

Hi,
I am a new to Maven. I wanted to convert my ANT project to Maven. I have multiple projects all sharing a common project name SharedLibrary. 

I want SharedLibrary to be build and the output Jar to be included whenever I run maven build of any of the project.

The directory structure is as follows

| - SharedLibrary|   ` pom.xml| - AdminWebApp|   ` pom.xml| - PublicWebApp|   ` pom.xml| - MediaProcessor    ` pom.xml

Can someone suggest me how this can be achieved?

Thanks in advanceNishant


      The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. http://in.yahoo.com/

Re: Sharing Module among Multiple Projects

Posted by Andreas Sewe <se...@st.informatik.tu-darmstadt.de>.
Nick Stolwijk wrote:
> Oh, I thought of another way:
> 
> Forget the whole profiles, just make one aggregator pom in the root
> level (so specify all the modules in there) and call Maven with:
> 
> mvn clean install --projects MediaProcessor --also-make
> 
> --projects (Shorthand: -pl) specifies which projects should be build
> --also-make (Shorthand: -am) specifies that also the dependencies of
> the projects should be build

Hey, that's a very useful tip. Thanks for this. :-)

Alas, it doesn't seem to work with a flat module layout. My aggregator 
POM hereby looks as follows:

   <modules>
     <module>../subproject</module>
   </modules>

But neither

   mvn clean install --projects '../subproject' --make-also

nor

   mvn clean install --projects subproject --make-also

work; in both cases Maven complains that it "couldn't find specified 
project in module list" (although the absolute path it prints out in the 
former case points to the correct submodule.) Do you have any idea of 
what I am doing wrong here?

Best wishes,

Andreas Sewe

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Sharing Module among Multiple Projects

Posted by Nick Stolwijk <ni...@gmail.com>.
I see two ways to have the shared module to build whenever you build
one of the other projects.

One is to use profiles.

 | - SharedLibrary
 |   ` pom.xml
 | - AdminWebApp
 |   ` pom.xml
 | - PublicWebApp
 |   ` pom.xml
 | - MediaProcessor
    ` pom.xml

Add a pom.xml at the root level and add profiles for each main project.

Like

<project>
   ...groupid artifactid version...

  <modules>
     <module>SharedLibrary</module>
  </modules>
  <profiles>
     <profile>
       <id>MediaProcessor</id>
       <modules>
           <module>MediaProcessor</module>
       </modules>
     </profile>
  </profiles>
</project>

Running maven at the root of the project with i.e. mvn clean install
-PMediaProcessor will build the two modules.

Oh, I thought of another way:

Forget the whole profiles, just make one aggregator pom in the root
level (so specify all the modules in there) and call Maven with:

mvn clean install --projects MediaProcessor --also-make

--projects (Shorthand: -pl) specifies which projects should be build
--also-make (Shorthand: -am) specifies that also the dependencies of
the projects should be build

With regards,

Nick Stolwijk
~Java Developer~

IPROFS BV.
Claus Sluterweg 125
2012 WS Haarlem
http://www.iprofs.nl



On Thu, Jan 21, 2010 at 10:32 AM, Nishant4 <nn...@yahoo.com> wrote:
>
>
> Nishant4 wrote:
>>
>> | - SharedLibrary|   ` pom.xml| - AdminWebApp|   ` pom.xml| -
>> PublicWebApp|   ` pom.xml| - MediaProcessor    ` pom.xml
>>
>
> Sorry, the formatting looks garbled. The directory structure is like this
>
> | - SharedLibrary
> |   ` pom.xml
> | - AdminWebApp
> |   ` pom.xml
> | - PublicWebApp
> |   ` pom.xml
> | - MediaProcessor
>    ` pom.xml
>
>
>
> --
> View this message in context: http://old.nabble.com/Sharing-Module-among-Multiple-Projects-tp27254872p27254996.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Sharing Module among Multiple Projects

Posted by Nishant4 <nn...@yahoo.com>.
ok. seems like this is a open issue http://jira.codehaus.org/browse/MWAR-192
-- 
View this message in context: http://old.nabble.com/Sharing-Module-among-Multiple-Projects-tp27254872p27261229.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Sharing Module among Multiple Projects

Posted by Nishant4 <nn...@yahoo.com>.
Thanks Karl, Nick -- the suggestions helped. 
It works, though there's a weird issue when I try to run mvn install from
Eclipse. It gives the following error:


> Reason: Failed to copy file for artifact[active project artifact:
> 	artifact = test.myproject:shared-library:jar:0.0.1-SNAPSHOT:compile;
>         ...
> 

However, this (mvn install) works fine if I run from command line.
Is there any thing that can be done at POM level to fix this. I do not think
approach like this [1] is good.

Any suggestions?

[1]
http://www.innovationontherun.com/common-issues-and-workarounds-while-building-ear-files-in-eclipse/

- Nishant
-- 
View this message in context: http://old.nabble.com/Sharing-Module-among-Multiple-Projects-tp27254872p27260845.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Sharing Module among Multiple Projects

Posted by Karl Heinz Marbaise <ka...@soebes.de>.
Hi,



> | - SharedLibrary
> |   ` pom.xml
> | - AdminWebApp
> |   ` pom.xml
> | - PublicWebApp
> |   ` pom.xml
> | - MediaProcessor
>     ` pom.xml
> 
If i understand your project correct all these "Modules" are needed for your
full project....

basically you can define the SharedLibrary as a dependency in each of your
parts AdminWebApp, PublicWebApp and MediaProcess (or which of your parts
uses the SharedLibrary)...

But i would suggest to create a parent:

  MyWebApp
   !        +-- pom.xml
   +--- SharedLib
            +-- pom.xml
   +--- AdminWebApp
            +-- pom.xml
   +--- PublicWebApp
            +-- pom.xml
   +--- MediaProcessor
            +-- pom.xml

and define in the root pom the modules


<modules>
  <module>AdminWebApp</module>
  <module>PublicWebApp</module>
  <module>MediaProcesssor</module>
  <module>SharedLibrary</module>
</modules>

and define inside the modules if it needs the SharedLibrary as dependency:

e.g. AdminWebApp:
   <dependencies>
    ...
    <dependency>
     <groupId>...</groupId>
     <artifactId>SharedLibrary</artifactId>
   </dependency>
  <dependencies>

and in all modules you have to give a parent:

  <parent>
     <groupId>...</groupId>
     <artifactId>mywebapp-parent</artifactId>
     <version>1.0-SNAPSHOT</version>
  </parent>

This will guaranty that the order of building is always correct, cause it
will be handled by Maven...

Just can simply can call mvn install or mvn package from the root of your
project....

Kind regards
Karl Heinz Marbaise
-- 
View this message in context: http://old.nabble.com/Sharing-Module-among-Multiple-Projects-tp27254872p27255259.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Sharing Module among Multiple Projects

Posted by Nishant4 <nn...@yahoo.com>.

Nishant4 wrote:
> 
> | - SharedLibrary|   ` pom.xml| - AdminWebApp|   ` pom.xml| -
> PublicWebApp|   ` pom.xml| - MediaProcessor    ` pom.xml
> 

Sorry, the formatting looks garbled. The directory structure is like this

| - SharedLibrary
|   ` pom.xml
| - AdminWebApp
|   ` pom.xml
| - PublicWebApp
|   ` pom.xml
| - MediaProcessor
    ` pom.xml



-- 
View this message in context: http://old.nabble.com/Sharing-Module-among-Multiple-Projects-tp27254872p27254996.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org