You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Vincent Massol <vm...@pivolis.com> on 2005/08/15 21:43:26 UTC

[m2] Is "sibling jars" use case supported?

Hi,

I'm just implementing the following use case in m1 and I'm wondering whether
it's already supported in m2.

Imagine you have a project that needs to generate 2 jars. The second jar is
almost exactly like the first one, except it contains a different config
file in it. You then want to deploy those 2 jars to a remote repo.

How would you do it?

In m1, I can see 2 solutions, both being a hack:

Solution 1:
- have 2 projects
- make the second projet depend on the first one's jar
- in a maven.xml file, modify the first project's jar to suit the need
- create a custom deploy goal using the artifact:deploy tag

BTW, I think this solution could be much improved by modifying the jar
plugin and allowing it to include a jar specified as dependency and tagged
(say with <jar.bundle>true</jar.bundle>). That may not be enough though if
the second jar needs to remove files from the first jar...

Solution 2:
- have a single project
- create a postgoal to jar:jar in maven.xml to create the second jar
- create a postgoal to jar:deploy to deploy the second jar using the
artifact:deploy tag

How would you it with m2? Using the assembly plugin in a second projet to
create a new jar out of the first one? And then deploy the created jar
(provided the assembly plugin is modified to add the generated jar as an
artifact proper - But that's being developed)?

Would you recommend having one project or 2?

I think one project makes more sense. Those 2 jars are really like an
ejb-jar and the ejb-client. Both made out of the same sources.

Thanks
-Vincent


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


RE: [m2] Is "sibling jars" use case supported?

Posted by Vincent Massol <vm...@pivolis.com>.

> -----Original Message-----
> From: Brett Porter [mailto:brett@apache.org]
> Sent: dimanche 21 août 2005 09:08
> To: Maven Developers List
> Subject: Re: [m2] Is "sibling jars" use case supported?
> 
> I don't understand a part of this - you talk about using dependency
> properties, but the only thing you want to change per jar is some config
> file in the JAR?

What I was suggesting below was to add a feature in the *m1* jar plugin that
allows to depend on other jars so that jars could be added to jars. A bit
like a simplified jarjar feature. I discussed it on IRC and it was pointed
to me that this was the goal of the m2 assembly plugin and that instead of
adding this feature to the m1 jar plugin it would be better to backport the
m2 assembly plugin...

I agreed but I don't have the time right now to do this backport.

In addition to this, my question here was on jars whereas I've found that my
use case was actually about ejb-jars... :-) Now the ejb plugin does support
depending on a jar but it does not unpack it so it was good enough for me. 

> What is the different config file? 

They are different deployment descriptors.

In the end I've implemented it using 3 projects: a common one producing a
jar and 2 others producing ejb-jars wrapping this jar with:

  <postGoal name="ejb:ejb">

    <ant:jar update="true" 
        destfile="${maven.ejb.build.dir}/${maven.ejb.final.name}">
      <ant:zipfileset 
          src="${pom.getDependencyPath(
            'com.sun.j2ee.blueprints:components-asyncsender-common')}"/>
    </ant:jar>

    <ant:jar update="true" 
        destfile="${maven.ejb.build.dir}/${maven.ejb.client.final.name}">
      <ant:zipfileset 
          src="${pom.getDependencyPath(
            'com.sun.j2ee.blueprints:components-asyncsender-common')}"
          excludes="${maven.ejb.client.base.excludes},
            ${maven.ejb.client.excludes}"/>
    </ant:jar>

  </postGoal>

Not very neat but I don't see any other solution right now apart from
either:

- backporting the assembly plugin
- adding a specific: ejb:modify-dd goal in the ejb plugin. But that would
require also adding new install and deploy goals to deploy the modified
ejb-jar and that's not scaling.

> If you always want to generate both,
> I think separate projects are ideal, where the second project uses the
> assembly plugin to repack the original JAR with the new config file.

Yep, that's what I was suggesting for m2 and I wanted confirmation. Thanks.
 
> If it is one jar produced twice for different environments, profiles are
> the right solution. In this way, only one jar is produced in the run,
> but the one produced depends on the target environment (using profiles).

Yes, that's another solution but that would require internally calling this
project twice from higher level projects as both ejb-jars are required to be
packaged in 2 different EARs (one standard and one admin). Now yes we could
probably bubble this up in the build so that there is a "standard" build and
an "admin one.

In any case, I was only really asking if there was a solution for this use
case in m2 and the answer is yes and it's the assembly plugin.

Don't worry for my m1 need as in the end I was doing this to transform the
Java Petstore Ant build for an article and in the end I'm using the
xPetstore instead and I don't have this need anymore.

[snip]

Thanks
-Vincent


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


Re: [m2] Is "sibling jars" use case supported?

Posted by Brett Porter <br...@apache.org>.
I don't understand a part of this - you talk about using dependency
properties, but the only thing you want to change per jar is some config
file in the JAR?

What is the different config file? If you always want to generate both,
I think separate projects are ideal, where the second project uses the
assembly plugin to repack the original JAR with the new config file.

If it is one jar produced twice for different environments, profiles are
the right solution. In this way, only one jar is produced in the run,
but the one produced depends on the target environment (using profiles).

- Brett

Vincent Massol wrote:

>Hi,
>
>I'm just implementing the following use case in m1 and I'm wondering whether
>it's already supported in m2.
>
>Imagine you have a project that needs to generate 2 jars. The second jar is
>almost exactly like the first one, except it contains a different config
>file in it. You then want to deploy those 2 jars to a remote repo.
>
>How would you do it?
>
>In m1, I can see 2 solutions, both being a hack:
>
>Solution 1:
>- have 2 projects
>- make the second projet depend on the first one's jar
>- in a maven.xml file, modify the first project's jar to suit the need
>- create a custom deploy goal using the artifact:deploy tag
>
>BTW, I think this solution could be much improved by modifying the jar
>plugin and allowing it to include a jar specified as dependency and tagged
>(say with <jar.bundle>true</jar.bundle>). That may not be enough though if
>the second jar needs to remove files from the first jar...
>
>Solution 2:
>- have a single project
>- create a postgoal to jar:jar in maven.xml to create the second jar
>- create a postgoal to jar:deploy to deploy the second jar using the
>artifact:deploy tag
>
>How would you it with m2? Using the assembly plugin in a second projet to
>create a new jar out of the first one? And then deploy the created jar
>(provided the assembly plugin is modified to add the generated jar as an
>artifact proper - But that's being developed)?
>
>Would you recommend having one project or 2?
>
>I think one project makes more sense. Those 2 jars are really like an
>ejb-jar and the ejb-client. Both made out of the same sources.
>
>Thanks
>-Vincent
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
>For additional commands, e-mail: dev-help@maven.apache.org
>
>
>  
>


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


RE: [m2] Is "sibling jars" use case supported?

Posted by Vincent Massol <vm...@pivolis.com>.
> -----Original Message-----
> From: Vincent Massol [mailto:vmassol@pivolis.com]
> Sent: lundi 15 août 2005 21:56
> To: 'Maven Developers List'
> Subject: RE: [m2] Is "sibling jars" use case supported?
> 
> 
> 
> > -----Original Message-----
> > From: Vincent Massol [mailto:vmassol@pivolis.com]
> > Sent: lundi 15 août 2005 21:43
> > To: 'Maven Developers List'
> > Subject: [m2] Is "sibling jars" use case supported?
> 
> [snip]
> 
> > BTW, I think this solution could be much improved by modifying the jar
> > plugin and allowing it to include a jar specified as dependency and
> tagged
> > (say with <jar.bundle>true</jar.bundle>). That may not be enough though
> if
> > the second jar needs to remove files from the first jar...
> 
> I think this could actually be easily implemented by having
> includes/excludes properties. For example:
> 
> <dependency>
>   [...]
>   <jar.bundle>true</jar.bundle>
>   <jar.bundle.includes>...</jar.bundle.includes>
>   <jar.bundle.excludes>...</<jar.bundle.excludes>
> </dependency>
> 
> The implementation would use a <zipfileset src="jar to include"
> includes="..." excludes="..."/>.
> 
> Hmm... interesting and not ahrd to do. I'll try implementing it in m1 for
> the fun.

Update: After discussing it on IRC I'm not going to implement it... It seems
the best solution would be to backport the m2 assembly plugin to m1 but I'll
defer this to later... ;-)

Thanks
-Vincent



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


RE: [m2] Is "sibling jars" use case supported?

Posted by Vincent Massol <vm...@pivolis.com>.

> -----Original Message-----
> From: Vincent Massol [mailto:vmassol@pivolis.com]
> Sent: lundi 15 août 2005 21:43
> To: 'Maven Developers List'
> Subject: [m2] Is "sibling jars" use case supported?

[snip]

> BTW, I think this solution could be much improved by modifying the jar
> plugin and allowing it to include a jar specified as dependency and tagged
> (say with <jar.bundle>true</jar.bundle>). That may not be enough though if
> the second jar needs to remove files from the first jar...

I think this could actually be easily implemented by having
includes/excludes properties. For example:

<dependency>
  [...]
  <jar.bundle>true</jar.bundle>
  <jar.bundle.includes>...</jar.bundle.includes>
  <jar.bundle.excludes>...</<jar.bundle.excludes>
</dependency>

The implementation would use a <zipfileset src="jar to include"
includes="..." excludes="..."/>.

Hmm... interesting and not ahrd to do. I'll try implementing it in m1 for
the fun.

-Vincent


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