You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by th...@bnpparibas.com on 2003/02/07 15:25:36 UTC

1 project <-> multiple jars, wars

Hi all,

Thanks for those who anwered to my previous mails, everything works fine
now !
Here is a deeper question...
We are migrating a J2EE project from an ANT build to a Maven build.

Our problem is that, in one subproject, we need to generate
different jars and wars from the same sources (client, server, webservice).
One would answer that we can divide this project into several subprojects,
but we don't want the same source code to be present in different projects.

So, the question is :
Is it possible to have one Maven project (with only one project.xml)
that generates multiple jars and wars ?
And if not, has anybody tried to customize Maven to do that ?

Thanks for your help.

Thomas




This message and any attachments (the "message") is
intended solely for the addressees and is confidential. 
If you receive this message in error, please delete it and 
immediately notify the sender. Any use not in accord with 
its purpose, any dissemination or disclosure, either whole 
or partial, is prohibited except formal approval. The internet
can not guarantee the integrity of this message. 
BNP PARIBAS (and its subsidiaries) shall (will) not 
therefore be liable for the message if modified. 

                ---------------------------------------------

Ce message et toutes les pieces jointes (ci-apres le 
"message") sont etablis a l'intention exclusive de ses 
destinataires et sont confidentiels. Si vous recevez ce 
message par erreur, merci de le detruire et d'en avertir 
immediatement l'expediteur. Toute utilisation de ce 
message non conforme a sa destination, toute diffusion 
ou toute publication, totale ou partielle, est interdite, sauf 
autorisation expresse. L'internet ne permettant pas 
d'assurer l'integrite de ce message, BNP PARIBAS (et ses
filiales) decline(nt) toute responsabilite au titre de ce 
message, dans l'hypothese ou il aurait ete modifie.


Re: 1 project <-> multiple jars, wars

Posted by Rafal Krzewski <Ra...@caltha.pl>.
thomas.durif@bnpparibas.com wrote:
> Hi all,
> 
> Thanks for those who anwered to my previous mails, everything works fine
> now !
> Here is a deeper question...
> We are migrating a J2EE project from an ANT build to a Maven build.
> 
> Our problem is that, in one subproject, we need to generate
> different jars and wars from the same sources (client, server, webservice).
> One would answer that we can divide this project into several subprojects,
> but we don't want the same source code to be present in different projects.
> 
> So, the question is :
> Is it possible to have one Maven project (with only one project.xml)
> that generates multiple jars and wars ?
> And if not, has anybody tried to customize Maven to do that ?

It is definetely possible without copying your sources around (which
would be the shortest path to chaos and misery).

One of your options would be creating a master project that contained
all the sources and a POM defining shared stuff (current version,
dependencies...) a few subprojects. Each of the subrojects would declare
that it's sources are in ${basedir}/../src/java

Another option would be defining overriding maven goals like java:jar
or jar:install in your project's maven.xml to do all the packaging work.

The one-to-one relationship between POM and generated artifact is one of
key concepts of maven. On the other hand it proves limiting in many
situations, and forces the users to do maven.xml hackery to subvert it.

I would dare saying that the POM<->artifact paradigm is not really
followed in almost any Maven project. Namely in virtuay any project
you generate your artifact (be it jar, war, or ear) AND the
documentation. The documentation could be packaged into a zip or tar.gz
and become a fully featured artifact built from your project (and it's POM).

I think that in the future Maven may be extended to support the single
POM -> multiple artifacts scenario. I think that it would not introduce
any conceptual problems into maven, as long as the artifacts are
explicitly declared in the pom. This way you could declare that your
project is able to generate server side ejb jar + client side ejb jar +
API documentation, or an ear + source tarball + developer documentation
tarball + user documentation tarball + a website.

R.




Re: 1 project <-> multiple jars, wars

Posted by Brian Ewins <Br...@btinternet.com>.

thomas.durif@bnpparibas.com wrote:
> Our problem is that, in one subproject, we need to generate
> different jars and wars from the same sources (client, server, webservice).
> One would answer that we can divide this project into several subprojects,
> but we don't want the same source code to be present in different projects.
I parse this as meaning: I use the same source to make different things, 
maven makes one jar per project, and I don't want multiple copies of the 
same project source to do this?

It seems to me that you could organize your source better. Build a jar. 
Use this jar in your webapp, webservice. Over time, break dependency 
cycles in the big fat jar and break out smaller jars, allowing your 
projects to depend on just the bits of code they need.
> 
> So, the question is :
> Is it possible to have one Maven project (with only one project.xml)
> that generates multiple jars and wars ?
> And if not, has anybody tried to customize Maven to do that ?

Yes its possible to do it this way too. Just add something appropriate 
in your project's maven.xml, e.g.

<?xml version="1.0" encoding="ISO-8859-1"?>
<project default="java:jar"
   xmlns:j="jelly:core">

   <goal name="leon"
     description="Bring me.... everyone.">
	<attainGoal name="java:jar"/>
	<attainGoal name="war:war"/>
   </goal>
</project>

Now "maven -f project.xml leon" builds the jar and the war. You can make 
your own goals to build multiple webapps if you like.

-Baz