You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@isis.apache.org by Kevin Meyer - KMZ <ke...@kmz.co.za> on 2011/05/25 20:35:08 UTC

Java help: splitting a master jar into multiple pieces...

Hi,

I've been banging my head against this - can someone tell me how to 
split a master jar into two (or three) pieces?

The maven shade plugin helps create a master jar (or war) that can be 
run with "java -jar xxx.jar" (e.g. running the todo html viewer project).
I've tested this, and as long as there is a "src/main/resources" that 
contains the "WEB-INF" directory (and its contents), this works fine.

But for upgrade purposes, I'd like to split this jar into 3: 1 contains all 
the "other" dependencies, 1 contains the "isis" classes, and the final 
contains the application "domain" classes. Then I can easily replace 
just the "domain.jar" as I update my application domain design...

I thought it'd be as simple as making three copies of the master jar 
and deleting the "other" bits from each one (i.e. "isis.jar" contains only 
the meta-inf directory and the "isis" directory, "dom.jar" contains only 
the application domain directories, and "others.jar" contains the rest).
Then execution could be as simple as: 
"java -cp others.jar:dom.jar -jar isis.jar"

But this fails almost immediately with an unable to find class error 
while looking for google's commons List class (which is now in 
"others.jar").

Any words of advice?  

Regards,
Kevin


Re: Java help: splitting a master jar into multiple pieces...

Posted by Kevin Meyer - KMZ <ke...@kmz.co.za>.
Hi Nour,

> Hey Kevin...
> 
>   Can you send me these jar to test them on my machine and see what happens ?
> 

It's the 14MB war/jar that is created with "mvn package" - for example, 
in the quickstart or archetype created "ToDo" application.

I'm about to try Dan's suggestion now.

Regards,
Kevin


Re: Java help: splitting a master jar into multiple pieces...

Posted by Mohammad Nour El-Din <no...@gmail.com>.
Hey Kevin...

  Can you send me these jar to test them on my machine and see what happens ?

On Wed, May 25, 2011 at 8:35 PM, Kevin Meyer - KMZ <ke...@kmz.co.za> wrote:
> Hi,
>
> I've been banging my head against this - can someone tell me how to
> split a master jar into two (or three) pieces?
>
> The maven shade plugin helps create a master jar (or war) that can be
> run with "java -jar xxx.jar" (e.g. running the todo html viewer project).
> I've tested this, and as long as there is a "src/main/resources" that
> contains the "WEB-INF" directory (and its contents), this works fine.
>
> But for upgrade purposes, I'd like to split this jar into 3: 1 contains all
> the "other" dependencies, 1 contains the "isis" classes, and the final
> contains the application "domain" classes. Then I can easily replace
> just the "domain.jar" as I update my application domain design...
>
> I thought it'd be as simple as making three copies of the master jar
> and deleting the "other" bits from each one (i.e. "isis.jar" contains only
> the meta-inf directory and the "isis" directory, "dom.jar" contains only
> the application domain directories, and "others.jar" contains the rest).
> Then execution could be as simple as:
> "java -cp others.jar:dom.jar -jar isis.jar"
>
> But this fails almost immediately with an unable to find class error
> while looking for google's commons List class (which is now in
> "others.jar").
>
> Any words of advice?
>
> Regards,
> Kevin
>
>



-- 
Thanks
- Mohammad Nour
  Author of (WebSphere Application Server Community Edition 2.0 User Guide)
  http://www.redbooks.ibm.com/abstracts/sg247585.html
- LinkedIn: http://www.linkedin.com/in/mnour
- Blog: http://tadabborat.blogspot.com
----
"Life is like riding a bicycle. To keep your balance you must keep moving"
- Albert Einstein

"Writing clean code is what you must do in order to call yourself a
professional. There is no reasonable excuse for doing anything less
than your best."
- Clean Code: A Handbook of Agile Software Craftsmanship

"Stay hungry, stay foolish."
- Steve Jobs

Re: Java help: splitting a master jar into multiple pieces...

Posted by Kevin Meyer - KMZ <ke...@kmz.co.za>.
Hi all,

I've discovered that the easist way to extract the local application 
domain resources out of a maven packaged bundle is to extract them 
as a bunch of jars - as stored in the standard war's WEB-INF/lib 
directory.

This way, they're easy to find, automatically packaged in a useful form 
by maven, and setup is simple (just a once-off edit of the Class-Path in 
the main jar).

Regards,
Kevin


On 25 May 2011 at 22:19, Dan Haywood wrote:

> Hi Kevin,
> It is possible to have the master jar reference other JARs, using the 
> Class-Path: entry in its META-INF/MANIFEST.MF file.  For details, see [1]
> 
> A separate problem is how to create the different JARs in the first 
> place.  Maven works best when you arrange it such that each module 
> creates a single artifact.  So I think you could create new plugins to 
> represent aech the different bits of the JAR that you want, and use the 
> shade plugin just in these dependent modules but *not* for the module 
> that will have the customised manifest.
> 
> HTH
> Dan
> 
> [1] http://download.oracle.com/javase/tutorial/deployment/jar/downman.html
> 


Re: Java help: splitting a master jar into multiple pieces...

Posted by Kevin Meyer - KMZ <ke...@kmz.co.za>.
Hi Dan,

Editting the META-INF/MANIFEST.MF to include a "Class-Path: " 
entry seems to do the trick.

As for creating the jars, I am currently manually creating the 3 jars by 
making copies of the output "war" from the (in this case, html-viewer 
module), as produced by "mvn -o clean package".
In each of the copies, I am deleting the parts that don't belong - i.e. in 
my "application domain" jar, I delete everything but the domain 
directories, etc.
The application domain jar also is the only jar to contain a Main Class 
statement in the manifest.

So, not fully automatic, but close enough. Now I can upload just 1 or 2 
portions to the client's server..

I may look into how to get the package plugin to automate this later.

Regards,
Kevin


On 25 May 2011 at 22:19, Dan Haywood wrote:

> Hi Kevin,
> It is possible to have the master jar reference other JARs, using the 
> Class-Path: entry in its META-INF/MANIFEST.MF file.  For details, see [1]
> 
> A separate problem is how to create the different JARs in the first 
> place.  Maven works best when you arrange it such that each module 
> creates a single artifact.  So I think you could create new plugins to 
> represent aech the different bits of the JAR that you want, and use the 
> shade plugin just in these dependent modules but *not* for the module 
> that will have the customised manifest.
> 
> HTH
> Dan
> 
> [1] http://download.oracle.com/javase/tutorial/deployment/jar/downman.html


Re: Java help: splitting a master jar into multiple pieces...

Posted by Dan Haywood <dk...@gmail.com>.
Hi Kevin,
It is possible to have the master jar reference other JARs, using the 
Class-Path: entry in its META-INF/MANIFEST.MF file.  For details, see [1]

A separate problem is how to create the different JARs in the first 
place.  Maven works best when you arrange it such that each module 
creates a single artifact.  So I think you could create new plugins to 
represent aech the different bits of the JAR that you want, and use the 
shade plugin just in these dependent modules but *not* for the module 
that will have the customised manifest.

HTH
Dan

[1] http://download.oracle.com/javase/tutorial/deployment/jar/downman.html


~~~~~~~~
On 25/05/2011 19:35, Kevin Meyer - KMZ wrote:
> Hi,
>
> I've been banging my head against this - can someone tell me how to
> split a master jar into two (or three) pieces?
>
> The maven shade plugin helps create a master jar (or war) that can be
> run with "java -jar xxx.jar" (e.g. running the todo html viewer project).
> I've tested this, and as long as there is a "src/main/resources" that
> contains the "WEB-INF" directory (and its contents), this works fine.
>
> But for upgrade purposes, I'd like to split this jar into 3: 1 contains all
> the "other" dependencies, 1 contains the "isis" classes, and the final
> contains the application "domain" classes. Then I can easily replace
> just the "domain.jar" as I update my application domain design...
>
> I thought it'd be as simple as making three copies of the master jar
> and deleting the "other" bits from each one (i.e. "isis.jar" contains only
> the meta-inf directory and the "isis" directory, "dom.jar" contains only
> the application domain directories, and "others.jar" contains the rest).
> Then execution could be as simple as:
> "java -cp others.jar:dom.jar -jar isis.jar"
>
> But this fails almost immediately with an unable to find class error
> while looking for google's commons List class (which is now in
> "others.jar").
>
> Any words of advice?
>
> Regards,
> Kevin
>
>