How to build multiple .jars from a single /src/ tree?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to build multiple .jars from a single /src/ tree?

/dev /local/ca
Using Apache Maven, I want to know the simplest way to build mutliple jar
files based on the package path from a single src/ directory hierarchy

I have src/com/pkg-path-one/.../ and src/com/pkg-path-two/.../

I am required to build one jar from src/pkg-path-one, and another jar from
src/com/pkg-path-two/.../

the repo I inherited does not have the typical layout: src/main/java/com
and so on, but starts at src/com
------------------------------

I am assuming two commands would need to be run specifying a target for
each jar (maybe - not sure), but having both jars built with a single
command would be helpful.

I am starting from ground zero with maven, so a full example of a pom.xml
would be helpful, if anyone has one around they have used for this in the
past.

thank you
Reply | Threaded
Open this post in threaded view
|

Re: How to build multiple .jars from a single /src/ tree?

Anders Hammar
This is not the right way to create two jars with Maven. It is possible to
do it, but you will likely run into other issues later on.
What you should do is create a multi-module project where you have one
module for each jar artifact you want to create.

There are numerous examples of multi-module projects on e.g. Github.

/Anders

On Fri, Oct 16, 2020 at 10:13 AM /dev /local/ca <[hidden email]>
wrote:

> Using Apache Maven, I want to know the simplest way to build mutliple jar
> files based on the package path from a single src/ directory hierarchy
>
> I have src/com/pkg-path-one/.../ and src/com/pkg-path-two/.../
>
> I am required to build one jar from src/pkg-path-one, and another jar from
> src/com/pkg-path-two/.../
>
> the repo I inherited does not have the typical layout: src/main/java/com
> and so on, but starts at src/com
> ------------------------------
>
> I am assuming two commands would need to be run specifying a target for
> each jar (maybe - not sure), but having both jars built with a single
> command would be helpful.
>
> I am starting from ground zero with maven, so a full example of a pom.xml
> would be helpful, if anyone has one around they have used for this in the
> past.
>
> thank you
>
Reply | Threaded
Open this post in threaded view
|

Re: How to build multiple .jars from a single /src/ tree?

Bernd Eckenfels
In reply to this post by /dev /local/ca
You can configure multiple jar creation runs (for example with the assembly or maven-jar-plugin) with include and exclude rules, which creates a second jar with a classifier. But derivations from a default build (one jar per module) should be done only if absolutely necessary. In the Long run it’s a good idea to restructure your projects and source directories for clean separation.

Gruss
Bernd
--
http://bernd.eckenfels.net
________________________________
Von: /dev /local/ca <[hidden email]>
Gesendet: Friday, October 16, 2020 10:12:50 AM
An: [hidden email] <[hidden email]>
Betreff: How to build multiple .jars from a single /src/ tree?

Using Apache Maven, I want to know the simplest way to build mutliple jar
files based on the package path from a single src/ directory hierarchy

I have src/com/pkg-path-one/.../ and src/com/pkg-path-two/.../

I am required to build one jar from src/pkg-path-one, and another jar from
src/com/pkg-path-two/.../

the repo I inherited does not have the typical layout: src/main/java/com
and so on, but starts at src/com
------------------------------

I am assuming two commands would need to be run specifying a target for
each jar (maybe - not sure), but having both jars built with a single
command would be helpful.

I am starting from ground zero with maven, so a full example of a pom.xml
would be helpful, if anyone has one around they have used for this in the
past.

thank you
Reply | Threaded
Open this post in threaded view
|

Re: How to build multiple .jars from a single /src/ tree?

/dev /local/ca
In reply to this post by Anders Hammar
Thank you Anders:

Do you have an example, or can point me to one on github?

On Fri, Oct 16, 2020 at 2:44 AM Anders Hammar <[hidden email]> wrote:

> This is not the right way to create two jars with Maven. It is possible to
> do it, but you will likely run into other issues later on.
> What you should do is create a multi-module project where you have one
> module for each jar artifact you want to create.
>
> There are numerous examples of multi-module projects on e.g. Github.
>
> /Anders
>
> On Fri, Oct 16, 2020 at 10:13 AM /dev /local/ca <[hidden email]>
> wrote:
>
> > Using Apache Maven, I want to know the simplest way to build mutliple jar
> > files based on the package path from a single src/ directory hierarchy
> >
> > I have src/com/pkg-path-one/.../ and src/com/pkg-path-two/.../
> >
> > I am required to build one jar from src/pkg-path-one, and another jar
> from
> > src/com/pkg-path-two/.../
> >
> > the repo I inherited does not have the typical layout: src/main/java/com
> > and so on, but starts at src/com
> > ------------------------------
> >
> > I am assuming two commands would need to be run specifying a target for
> > each jar (maybe - not sure), but having both jars built with a single
> > command would be helpful.
> >
> > I am starting from ground zero with maven, so a full example of a pom.xml
> > would be helpful, if anyone has one around they have used for this in the
> > past.
> >
> > thank you
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: How to build multiple .jars from a single /src/ tree?

Anders Hammar
You can have a look at the source code for Maven itself.

/Anders (mobile)

Den fre 16 okt. 2020 16:45/dev /local/ca <[hidden email]> skrev:

> Thank you Anders:
>
> Do you have an example, or can point me to one on github?
>
> On Fri, Oct 16, 2020 at 2:44 AM Anders Hammar <[hidden email]> wrote:
>
> > This is not the right way to create two jars with Maven. It is possible
> to
> > do it, but you will likely run into other issues later on.
> > What you should do is create a multi-module project where you have one
> > module for each jar artifact you want to create.
> >
> > There are numerous examples of multi-module projects on e.g. Github.
> >
> > /Anders
> >
> > On Fri, Oct 16, 2020 at 10:13 AM /dev /local/ca <[hidden email]>
> > wrote:
> >
> > > Using Apache Maven, I want to know the simplest way to build mutliple
> jar
> > > files based on the package path from a single src/ directory hierarchy
> > >
> > > I have src/com/pkg-path-one/.../ and src/com/pkg-path-two/.../
> > >
> > > I am required to build one jar from src/pkg-path-one, and another jar
> > from
> > > src/com/pkg-path-two/.../
> > >
> > > the repo I inherited does not have the typical layout:
> src/main/java/com
> > > and so on, but starts at src/com
> > > ------------------------------
> > >
> > > I am assuming two commands would need to be run specifying a target for
> > > each jar (maybe - not sure), but having both jars built with a single
> > > command would be helpful.
> > >
> > > I am starting from ground zero with maven, so a full example of a
> pom.xml
> > > would be helpful, if anyone has one around they have used for this in
> the
> > > past.
> > >
> > > thank you
> > >
> >
>