You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Ryan Wexler <ry...@iridiumsuite.com> on 2012/03/08 04:45:08 UTC

maven-shade-plugin classpath

I am using the ManifestResourceTransformer of the maven shade plugin to
create an executable jar from an existing jar.

I would also like to add the classpath and set a classpathprefix like you
can do using the normal maven jar.
    <addClasspath>true</addClasspath>
    <classpathPrefix>lib/</classpathPrefix>

Is there a way to do this with the shade plugin?

thanks

Re: maven-shade-plugin classpath

Posted by Ron Wheeler <rw...@artifact-software.com>.
This is POM that we used to build a batch job that modified the database 
that was supporting a 60 WAR LMS project.
A lot of the dependencies were on code that was shared across a lot of 
WAR projects

I hope that the POM and the jar-with-dependencies-assembly.xml file 
listings help you
As you can see we used the maven-assembly-plugin rather than shade so it 
is not quite the same. I am not sure what extra stuff shade gives but we 
never used it even though we had to generate several batch jobs.
As you can see, we never had to do much with classpaths. Maven seemed to 
know how to build the jar so that it worked with no problems. It only 
needed to know what to start running when java started it
<manifest>
<mainClass>com.artifact_software.lms.contractrenew.main.ContractRenewBatchMain</mainClass>
<packageName>com.artifact_software.lms.contractrenew.main</packageName>
</manifest>

I hope that this helps

Ron


------------------------------------------------------------------------------------------------------------------------------------
POM

<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd">

<parent>
<artifactId>lms-pom-master</artifactId>
<groupId>com.artifact_software.lms</groupId>
<version>1.9.1</version>
</parent>

<modelVersion>4.0.0</modelVersion>

<groupId>com.artifact_software.lms</groupId>
<artifactId>lms-contractrenew-batch</artifactId>
<packaging>jar</packaging>
<version>1.11.3</version>

<name>Contract Auto Renew Application</name>

<description>Contract Auto Renew Application</description>
<prerequisites>
<maven>2.0.4</maven>
</prerequisites>

<build>
<sourceDirectory>src</sourceDirectory>
<plugins>

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>jar-with-dependencies-assembly.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>com.artifact_software.lms.contractrenew.main.ContractRenewBatchMain</mainClass>
<packageName>com.artifact_software.lms.contractrenew.main</packageName>
</manifest>
<manifestEntries>
<mode>development</mode>
<url>${pom.url}</url>
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.artifact_software.lms</groupId>
<artifactId>lms-pom-lms-libraries</artifactId>
<version>1.11.1</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
<dependency>
.
.
.Lots more of them here.
.
</dependency>
</dependencies>

</project>
----------------------------------------------------
jar-with-dependencies-assembly.xml
---------------------
<assembly>
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory></outputDirectory>
<outputFileNameMapping></outputFileNameMapping>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>

</assembly>

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

Ron
>> What I can see from your description is a pretty standard set of projects
>> that should not require any special set up or plug-ins.
>> It looks like a few jar POMs to make your libraries from your code, a war
>> POM to make the WAR using the WAR plug-in and another jar POM to make the
>> executable.
>>
>> Google for "maven executable jar" gives lots of listings including this
>> gem.
>>
>>
>> http://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html
>>
>>
> The shade plugin adds the main class to the manifest perfectly, but I don't
> see how I can add the classpath reference?
>
>


-- 
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102



Re: maven-shade-plugin classpath

Posted by Ryan Wexler <ry...@iridiumsuite.com>.
On Thu, Mar 8, 2012 at 11:29 AM, Ron Wheeler <rwheeler@artifact-software.com
> wrote:

>  A Maven parent does not contain any code but manages default setting for
> a project (versions of dependencies and deployment specifications) but I
> think that I understand what you might mean.
>
> I am using that word "parent" incorrectly in the context of maven.  It
isn't a maven "parent' per se, but rather just a maven project that is only
deployed via other maven projects that depend on it.   Since this code is
reused in several places, I thought it made sense to make a generic jar
project that the other projects can pull from.



> It looks like you should have one or more code projects that produce jars
> that are dependencies for other projects. This is pretty standard.
>
> You seem to have a project that creates a war file. It should depend on
> the other project's artifacts in order to get their jar files into the
> right place in the war file.
> This is pretty standard and maven knows how to built war files.
>

The war projects that depend on this code is able to bring in the jar no
problem and it works well.


>
> The project that produces a jar sounds like it is trying to produce a
> standalone executable. If its dependencies are set to point to the
> libraries that it needs, you should get an executable jar all set up and
> ready to be run. Maven knows how to do this.
> You don't have to worry about classpaths or any of that stuff.
>
> Well I am taking a generic non-executable jar that has no classpath or
main class referenced in the manifest and trying to convert it into an
executable code that also references its dependencies in the manifest's
classpath.  There are several variations of this result so that is why the
original jar and its manifest is so generic .



> What I can see from your description is a pretty standard set of projects
> that should not require any special set up or plug-ins.
> It looks like a few jar POMs to make your libraries from your code, a war
> POM to make the WAR using the WAR plug-in and another jar POM to make the
> executable.
>
> Google for "maven executable jar" gives lots of listings including this
> gem.
>
>
> http://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html
>
>
The shade plugin adds the main class to the manifest perfectly, but I don't
see how I can add the classpath reference?


> Why do you need to play with the manifest?
> Are you building something so unusual that Maven has not been used to do
> this before?
>
> Ron
>
> Unfortunately, as a maven newbie, all this is new.  Thanks for the reply
Ron!


>
>
>
> On 08/03/2012 1:25 PM, Ryan Wexler wrote:
>
> Essentially I have a source code module and dependencies in a parent
> project as a jar.  There are several projects which depend on it.  For
> instance it is used in a war project.
> Another project that depends on it needs to produce am executable jar from
> the same code and the manifest needs to reference all the dependencies in
> the classpath with the prefix 'lib'.
>  On Mar 8, 2012 9:21 AM, "Ron Wheeler" <rw...@artifact-software.com>
> wrote:
>
>> Sound interesting but what are you trying to make in the end?
>>
>> What is the 30,000 ft view of the problem?
>>
>> Ron
>>
>> On 08/03/2012 12:03 PM, Ryan Wexler wrote:
>>
>>> On Thu, Mar 8, 2012 at 8:36 AM, Wayne Fay<wa...@gmail.com>  wrote:
>>>
>>>  I would also like to add the classpath and set a classpathprefix like
>>>>> you
>>>>> can do using the normal maven jar.
>>>>>    <addClasspath>true</addClasspath>
>>>>>    <classpathPrefix>lib/</classpathPrefix>
>>>>>
>>>>> Is there a way to do this with the shade plugin?
>>>>>
>>>> Generally, the thinking with Shade is that you are building an
>>>> "uber-jar" that is going to contain the contents all your dependency
>>>> jars along with your own code, so there should be no need to specify a
>>>> classpath since it is all in one single jar file.
>>>>
>>>> What is your requirement?
>>>>
>>>>
>>>>  I am essentially creating a jar from a jar.  I was not intent on
>>> embedding
>>> my dependencies, so maybe this is the wrong tool.
>>>
>>> I was more interested as to the extent to which you can customize a jar
>>> using the ManifestResourceTransformer.  My initial thought is that it
>>> could
>>> inherit all of a jar artificat's dependencies and then affect that jar
>>> just
>>> like you were using the jar plugin.  But my thought process maybe wrong
>>> here.
>>>
>>> Maybe what I want instead is to unpack a jar artifact and it's
>>> dependencies
>>> and then recreate the jar from scratch.  Not sure how you unpack it's
>>> dependencies though.
>>>
>>> Wayne
>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>>> For additional commands, e-mail: users-help@maven.apache.org
>>>>
>>>>
>>>>
>>
>> --
>> Ron Wheeler
>> President
>> Artifact Software Inc
>> email: rwheeler@artifact-software.com
>> skype: ronaldmwheeler
>> phone: 866-970-2435, ext 102
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>
>
> --
> Ron Wheeler
> President
> Artifact Software Inc
> email: rwheeler@artifact-software.com
> skype: ronaldmwheeler
> phone: 866-970-2435, ext 102
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>

Re: maven-shade-plugin classpath

Posted by Ron Wheeler <rw...@artifact-software.com>.
A Maven parent does not contain any code but manages default setting for 
a project (versions of dependencies and deployment specifications) but I 
think that I understand what you might mean.

It looks like you should have one or more code projects that produce 
jars that are dependencies for other projects. This is pretty standard.

You seem to have a project that creates a war file. It should depend on 
the other project's artifacts in order to get their jar files into the 
right place in the war file.
This is pretty standard and maven knows how to built war files.

The project that produces a jar sounds like it is trying to produce a 
standalone executable. If its dependencies are set to point to the 
libraries that it needs, you should get an executable jar all set up and 
ready to be run. Maven knows how to do this.
You don't have to worry about classpaths or any of that stuff.

What I can see from your description is a pretty standard set of 
projects that should not require any special set up or plug-ins.
It looks like a few jar POMs to make your libraries from your code, a 
war POM to make the WAR using the WAR plug-in and another jar POM to 
make the executable.

Google for "maven executable jar" gives lots of listings including this gem.

http://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html

Why do you need to play with the manifest?
Are you building something so unusual that Maven has not been used to do 
this before?

Ron



On 08/03/2012 1:25 PM, Ryan Wexler wrote:
>
> Essentially I have a source code module and dependencies in a parent 
> project as a jar.  There are several projects which depend on it.  For 
> instance it is used in a war project.
> Another project that depends on it needs to produce am executable jar 
> from the same code and the manifest needs to reference all the 
> dependencies in the classpath with the prefix 'lib'.
>
> On Mar 8, 2012 9:21 AM, "Ron Wheeler" <rwheeler@artifact-software.com 
> <ma...@artifact-software.com>> wrote:
>
>     Sound interesting but what are you trying to make in the end?
>
>     What is the 30,000 ft view of the problem?
>
>     Ron
>
>     On 08/03/2012 12:03 PM, Ryan Wexler wrote:
>
>         On Thu, Mar 8, 2012 at 8:36 AM, Wayne Fay<waynefay@gmail.com
>         <ma...@gmail.com>>  wrote:
>
>                 I would also like to add the classpath and set a
>                 classpathprefix like you
>                 can do using the normal maven jar.
>                 <addClasspath>true</addClasspath>
>                 <classpathPrefix>lib/</classpathPrefix>
>
>                 Is there a way to do this with the shade plugin?
>
>             Generally, the thinking with Shade is that you are building an
>             "uber-jar" that is going to contain the contents all your
>             dependency
>             jars along with your own code, so there should be no need
>             to specify a
>             classpath since it is all in one single jar file.
>
>             What is your requirement?
>
>
>         I am essentially creating a jar from a jar.  I was not intent
>         on embedding
>         my dependencies, so maybe this is the wrong tool.
>
>         I was more interested as to the extent to which you can
>         customize a jar
>         using the ManifestResourceTransformer.  My initial thought is
>         that it could
>         inherit all of a jar artificat's dependencies and then affect
>         that jar just
>         like you were using the jar plugin.  But my thought process
>         maybe wrong
>         here.
>
>         Maybe what I want instead is to unpack a jar artifact and it's
>         dependencies
>         and then recreate the jar from scratch.  Not sure how you
>         unpack it's
>         dependencies though.
>
>         Wayne
>
>             ---------------------------------------------------------------------
>             To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>             <ma...@maven.apache.org>
>             For additional commands, e-mail:
>             users-help@maven.apache.org
>             <ma...@maven.apache.org>
>
>
>
>
>     -- 
>     Ron Wheeler
>     President
>     Artifact Software Inc
>     email: rwheeler@artifact-software.com
>     <ma...@artifact-software.com>
>     skype: ronaldmwheeler
>     phone: 866-970-2435, ext 102 <tel:866-970-2435%2C%20ext%20102>
>
>
>
>
>     ---------------------------------------------------------------------
>     To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>     <ma...@maven.apache.org>
>     For additional commands, e-mail: users-help@maven.apache.org
>     <ma...@maven.apache.org>
>


-- 
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102


Re: maven-shade-plugin classpath

Posted by Ryan Wexler <ry...@iridiumsuite.com>.
Essentially I have a source code module and dependencies in a parent
project as a jar.  There are several projects which depend on it.  For
instance it is used in a war project.
Another project that depends on it needs to produce am executable jar from
the same code and the manifest needs to reference all the dependencies in
the classpath with the prefix 'lib'.
 On Mar 8, 2012 9:21 AM, "Ron Wheeler" <rw...@artifact-software.com>
wrote:

> Sound interesting but what are you trying to make in the end?
>
> What is the 30,000 ft view of the problem?
>
> Ron
>
> On 08/03/2012 12:03 PM, Ryan Wexler wrote:
>
>> On Thu, Mar 8, 2012 at 8:36 AM, Wayne Fay<wa...@gmail.com>  wrote:
>>
>>  I would also like to add the classpath and set a classpathprefix like you
>>>> can do using the normal maven jar.
>>>>    <addClasspath>true</**addClasspath>
>>>>    <classpathPrefix>lib/</**classpathPrefix>
>>>>
>>>> Is there a way to do this with the shade plugin?
>>>>
>>> Generally, the thinking with Shade is that you are building an
>>> "uber-jar" that is going to contain the contents all your dependency
>>> jars along with your own code, so there should be no need to specify a
>>> classpath since it is all in one single jar file.
>>>
>>> What is your requirement?
>>>
>>>
>>>  I am essentially creating a jar from a jar.  I was not intent on
>> embedding
>> my dependencies, so maybe this is the wrong tool.
>>
>> I was more interested as to the extent to which you can customize a jar
>> using the ManifestResourceTransformer.  My initial thought is that it
>> could
>> inherit all of a jar artificat's dependencies and then affect that jar
>> just
>> like you were using the jar plugin.  But my thought process maybe wrong
>> here.
>>
>> Maybe what I want instead is to unpack a jar artifact and it's
>> dependencies
>> and then recreate the jar from scratch.  Not sure how you unpack it's
>> dependencies though.
>>
>> Wayne
>>
>>> ------------------------------**------------------------------**
>>> ---------
>>> To unsubscribe, e-mail: users-unsubscribe@maven.**apache.org<us...@maven.apache.org>
>>> For additional commands, e-mail: users-help@maven.apache.org
>>>
>>>
>>>
>
> --
> Ron Wheeler
> President
> Artifact Software Inc
> email: rwheeler@artifact-software.com
> skype: ronaldmwheeler
> phone: 866-970-2435, ext 102
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>

Re: maven-shade-plugin classpath

Posted by Ron Wheeler <rw...@artifact-software.com>.
Sound interesting but what are you trying to make in the end?

What is the 30,000 ft view of the problem?

Ron

On 08/03/2012 12:03 PM, Ryan Wexler wrote:
> On Thu, Mar 8, 2012 at 8:36 AM, Wayne Fay<wa...@gmail.com>  wrote:
>
>>> I would also like to add the classpath and set a classpathprefix like you
>>> can do using the normal maven jar.
>>>     <addClasspath>true</addClasspath>
>>>     <classpathPrefix>lib/</classpathPrefix>
>>>
>>> Is there a way to do this with the shade plugin?
>> Generally, the thinking with Shade is that you are building an
>> "uber-jar" that is going to contain the contents all your dependency
>> jars along with your own code, so there should be no need to specify a
>> classpath since it is all in one single jar file.
>>
>> What is your requirement?
>>
>>
> I am essentially creating a jar from a jar.  I was not intent on embedding
> my dependencies, so maybe this is the wrong tool.
>
> I was more interested as to the extent to which you can customize a jar
> using the ManifestResourceTransformer.  My initial thought is that it could
> inherit all of a jar artificat's dependencies and then affect that jar just
> like you were using the jar plugin.  But my thought process maybe wrong
> here.
>
> Maybe what I want instead is to unpack a jar artifact and it's dependencies
> and then recreate the jar from scratch.  Not sure how you unpack it's
> dependencies though.
>
> Wayne
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>


-- 
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102



Re: maven-shade-plugin classpath

Posted by Ryan Wexler <ry...@iridiumsuite.com>.
On Thu, Mar 8, 2012 at 8:36 AM, Wayne Fay <wa...@gmail.com> wrote:

> > I would also like to add the classpath and set a classpathprefix like you
> > can do using the normal maven jar.
> >    <addClasspath>true</addClasspath>
> >    <classpathPrefix>lib/</classpathPrefix>
> >
> > Is there a way to do this with the shade plugin?
>
> Generally, the thinking with Shade is that you are building an
> "uber-jar" that is going to contain the contents all your dependency
> jars along with your own code, so there should be no need to specify a
> classpath since it is all in one single jar file.
>
> What is your requirement?
>
>
I am essentially creating a jar from a jar.  I was not intent on embedding
my dependencies, so maybe this is the wrong tool.

I was more interested as to the extent to which you can customize a jar
using the ManifestResourceTransformer.  My initial thought is that it could
inherit all of a jar artificat's dependencies and then affect that jar just
like you were using the jar plugin.  But my thought process maybe wrong
here.

Maybe what I want instead is to unpack a jar artifact and it's dependencies
and then recreate the jar from scratch.  Not sure how you unpack it's
dependencies though.

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

Re: maven-shade-plugin classpath

Posted by Wayne Fay <wa...@gmail.com>.
> I would also like to add the classpath and set a classpathprefix like you
> can do using the normal maven jar.
>    <addClasspath>true</addClasspath>
>    <classpathPrefix>lib/</classpathPrefix>
>
> Is there a way to do this with the shade plugin?

Generally, the thinking with Shade is that you are building an
"uber-jar" that is going to contain the contents all your dependency
jars along with your own code, so there should be no need to specify a
classpath since it is all in one single jar file.

What is your requirement?

Wayne

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