Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Adding arbitrary resources to jar
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Chas Emerick  
View profile  
 More options Oct 10 2011, 1:15 pm
From: Chas Emerick <cemer...@snowtide.com>
Date: Mon, 10 Oct 2011 13:15:21 -0400
Local: Mon, Oct 10 2011 1:15 pm
Subject: Adding arbitrary resources to jar
I need to produce a jar file that contains some files rooted in multiple directories, and all of the contents of some set of other jar files in the project (no, they're not dependencies, sadly).  In other words, the rough equivalent of the assembly plugin in maven.

I've been fiddling around with hooking leiningen.jar/filespecs and uberjar/write-components, with limited success.

Is there an obvious alternative that I'm missing?

Thanks,

- Chas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Phil Hagelberg  
View profile  
 More options Oct 10 2011, 1:24 pm
From: Phil Hagelberg <p...@hagelb.org>
Date: Mon, 10 Oct 2011 10:24:49 -0700
Local: Mon, Oct 10 2011 1:24 pm
Subject: Re: Adding arbitrary resources to jar

On Mon, Oct 10, 2011 at 10:15 AM, Chas Emerick <cemer...@snowtide.com> wrote:
> I need to produce a jar file that contains some files rooted in multiple directories, and all of the contents of some set of other jar files in the project (no, they're not dependencies, sadly).  In other words, the rough equivalent of the assembly plugin in maven.

> Is there an obvious alternative that I'm missing?

No, right now all we've got is the single :resources-path config
value. Are these things that need to be both on the classpath and in
the jar, or just the latter?

-Phil


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chas Emerick  
View profile  
 More options Oct 10 2011, 1:42 pm
From: Chas Emerick <cemer...@snowtide.com>
Date: Mon, 10 Oct 2011 10:42:18 -0700 (PDT)
Local: Mon, Oct 10 2011 1:42 pm
Subject: Re: Adding arbitrary resources to jar

On Oct 10, 1:24 pm, Phil Hagelberg <p...@hagelb.org> wrote:

> On Mon, Oct 10, 2011 at 10:15 AM, Chas Emerick <cemer...@snowtide.com> wrote:
> > I need to produce a jar file that contains some files rooted in multiple directories, and all of the contents of some set of other jar files in the project (no, they're not dependencies, sadly).  In other words, the rough equivalent of the assembly plugin in maven.

> > Is there an obvious alternative that I'm missing?

> No, right now all we've got is the single :resources-path config
> value. Are these things that need to be both on the classpath and in
> the jar, or just the latter?

> -Phil

In this case, both.  The REPL case is handled by :extra-classpath-dirs
(seems to work for jars in there as well as directory paths), but
that's less important to me at this point.

It's honestly a stupid scenario that I wouldn't expect project.clj to
support directly, but I did expect an API to be available for such
things (e.g. "make a jar out of this, that, and the other thing").
The copy-to-jar multimethod is going in the right direction.  I'm
surprised that uberjar didn't build on top of that, actually.

- Chas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chas Emerick  
View profile  
 More options Oct 10 2011, 10:55 pm
From: Chas Emerick <cemer...@snowtide.com>
Date: Mon, 10 Oct 2011 22:55:25 -0400
Local: Mon, Oct 10 2011 10:55 pm
Subject: Re: Adding arbitrary resources to jar

On Oct 10, 2011, at 1:42 PM, Chas Emerick wrote:

I've patched together a solution, though it's fugly.  Take this as an experience report, or something. :-)

First, a :jar implementation of copy-to-jar for the curious:

(defmethod leiningen.jar/copy-to-jar :jar
  [project jar-os spec]
  (let [f (java.util.jar.JarFile. (:jar spec))]
    (doseq [entry (enumeration-seq (.entries f))
            :when (not (-> entry .getName (.startsWith "META-INF")))]
      (.putNextEntry jar-os entry)
      (io/copy (.getInputStream f entry) jar-os))))

The :when clause is unfortunate, but lein.jar doesn't have the same notion of duplicate entry skipping that lein.uberjar does.

Add the above with a hook on lein.jar/filespecs to inject the necessary :path and :jar entries, and I'm good…*except* when I run `clean` prior to `jar`.  If I run `lein clean, jar`, the jar fn gets run twice — one with my hook, one without my hook, and I end up getting a duplicate jar entry exception.  Leave off the `clean`, and all's well.  I don't have a theory about why that is at the moment.

In general, it seems like lein.jar, lein.uberjar, and e.g. lein.ring.war all have bits and pieces of what would be a properly comprehensive zip/jar API, but none of them have them all in one spot (e.g. lein.jar is the only one that is openly extensible and attempts to get away from procedurally building archives, only uberjar does duplicate entry skipping, and ring.war is the only one that allows for re-rooting of content from 'filespecs').

I wonder if I'm the only one that has this impression, or if others are simply making do with other methods.

Cheers,

- Chas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matjaz Gregoric  
View profile  
 More options Oct 11 2011, 4:05 am
From: Matjaz Gregoric <gre...@gmail.com>
Date: Tue, 11 Oct 2011 10:05:15 +0200
Local: Tues, Oct 11 2011 4:05 am
Subject: Re: Adding arbitrary resources to jar

> In general, it seems like lein.jar, lein.uberjar, and e.g. lein.ring.war
> all have bits and pieces of what would be a properly comprehensive zip/jar
> API, but none of them have them all in one spot (e.g. lein.jar is the only
> one that is openly extensible and attempts to get away from procedurally
> building archives, only uberjar does duplicate entry skipping, and ring.war
> is the only one that allows for re-rooting of content from 'filespecs').

> I wonder if I'm the only one that has this impression, or if others are
> simply making do with other methods.

You're not the only one, I've had similar problems recently, and had to
resort to ugly workarounds. It would be very nice if the code/APIs could be
cleaned up and made more extensible.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Phil Hagelberg  
View profile  
 More options Oct 13 2011, 2:28 am
From: Phil Hagelberg <p...@hagelb.org>
Date: Wed, 12 Oct 2011 23:28:36 -0700
Local: Thurs, Oct 13 2011 2:28 am
Subject: Re: Adding arbitrary resources to jar

On Mon, Oct 10, 2011 at 7:55 PM, Chas Emerick <cemer...@snowtide.com> wrote:
> In general, it seems like lein.jar, lein.uberjar, and e.g. lein.ring.war all have bits and pieces of what would be a properly comprehensive zip/jar API, but none of them have them all in one spot (e.g. lein.jar is the only one that is openly extensible and attempts to get away from procedurally building archives, only uberjar does duplicate entry skipping, and ring.war is the only one that allows for re-rooting of content from 'filespecs').

This is exactly the kind of thing I hope to address in 2.0 when we
have a chance to really break APIs, so I'm glad you brought it up.
I'll make sure these issues are addressed.

-Phil


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chas Emerick  
View profile  
 More options Oct 13 2011, 5:09 am
From: Chas Emerick <cemer...@snowtide.com>
Date: Thu, 13 Oct 2011 05:09:07 -0400
Local: Thurs, Oct 13 2011 5:09 am
Subject: Re: Adding arbitrary resources to jar

On Oct 13, 2011, at 2:28 AM, Phil Hagelberg wrote:

> On Mon, Oct 10, 2011 at 7:55 PM, Chas Emerick <cemer...@snowtide.com> wrote:
>> In general, it seems like lein.jar, lein.uberjar, and e.g. lein.ring.war all have bits and pieces of what would be a properly comprehensive zip/jar API, but none of them have them all in one spot (e.g. lein.jar is the only one that is openly extensible and attempts to get away from procedurally building archives, only uberjar does duplicate entry skipping, and ring.war is the only one that allows for re-rooting of content from 'filespecs').

> This is exactly the kind of thing I hope to address in 2.0 when we
> have a chance to really break APIs, so I'm glad you brought it up.
> I'll make sure these issues are addressed.

Good to know. :-)

If anyone's curious, they can look at what I ended up with:

https://github.com/cemerick/clutch-clojurescript/blob/master/project.clj

I punted on the directories and just unpacked them into /resources.  I never did figure out why `clean, jar` ran my hook twice compared to just `jar`.

Hopefully developments elsewhere will allow me to eliminate that particular hairball entirely. :-)

- Chas


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »