You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@buildr.apache.org by tommycli <to...@ucla.edu> on 2009/11/27 09:44:56 UTC

Including dependencies with a JAR package

I use buildr with the transitive compile.with artifact specifications.

My problem is this: After buildr makes its package, I have a nice JAR file,
but I cannot run it without its dependency JARs.

I don't even know which JARs it depends on. How do you find out which JARs
you need to distribute with your project? Can buildr package all of it into
one file?

Tommy
-- 
View this message in context: http://old.nabble.com/Including-dependencies-with-a-JAR-package-tp26537708p26537708.html
Sent from the Buildr - User mailing list archive at Nabble.com.


Re: Including dependencies with a JAR package

Posted by Alex Boisvert <al...@gmail.com>.
Neat!  I added this to our How-To section.

http://cwiki.apache.org/confluence/display/BUILDR/How+to+include+dependencies+in+.jar+packages

Thanks for sharing.

alex


On Fri, Nov 27, 2009 at 4:31 AM, Levin Alexander
<le...@gmail.com>wrote:

> On Fri, Nov 27, 2009 at 9:44 AM, tommycli <to...@ucla.edu> wrote:
> >
> > I use buildr with the transitive compile.with artifact specifications.
> >
> > My problem is this: After buildr makes its package, I have a nice JAR
> file,
> > but I cannot run it without its dependency JARs.
> >
> > I don't even know which JARs it depends on. How do you find out which
> JARs
> > you need to distribute with your project? Can buildr package all of it
> into
> > one file?
>
> I am using autojar with builder to find and bundle dependencies to the Jar:
>
> def add_dependencies(pkg)
>  tempfile = pkg.to_s.sub(/.jar$/, "-without-dependencies.jar")
>  mv pkg.to_s, tempfile
>
>  dependencies = compile.dependencies.map { |d| "-c #{d}"}.join(" ")
>  sh "java -jar tools/autojar.jar -baev -o #{pkg} #{dependencies}
> #{tempfile}"
> end
>
> package(:jar).enhance { |pkg| pkg.enhance { |pkg| add_dependencies(pkg) }}
>
> <
> http://stackoverflow.com/questions/1279419/buildr-package-dependencies-into-a-single-jar/1285293#1285293
> >
>
> this is a hack and potentially has problems (it uses autojar's
> dependency resolution mechanism and therefore cannot find dynamically
> added dependencies) but for us it works quite well in practice.
>
> -Levin
>

Re: Including dependencies with a JAR package

Posted by Levin Alexander <le...@gmail.com>.
On Fri, Nov 27, 2009 at 9:44 AM, tommycli <to...@ucla.edu> wrote:
>
> I use buildr with the transitive compile.with artifact specifications.
>
> My problem is this: After buildr makes its package, I have a nice JAR file,
> but I cannot run it without its dependency JARs.
>
> I don't even know which JARs it depends on. How do you find out which JARs
> you need to distribute with your project? Can buildr package all of it into
> one file?

I am using autojar with builder to find and bundle dependencies to the Jar:

def add_dependencies(pkg)
  tempfile = pkg.to_s.sub(/.jar$/, "-without-dependencies.jar")
  mv pkg.to_s, tempfile

  dependencies = compile.dependencies.map { |d| "-c #{d}"}.join(" ")
  sh "java -jar tools/autojar.jar -baev -o #{pkg} #{dependencies} #{tempfile}"
end

package(:jar).enhance { |pkg| pkg.enhance { |pkg| add_dependencies(pkg) }}

<http://stackoverflow.com/questions/1279419/buildr-package-dependencies-into-a-single-jar/1285293#1285293>

this is a hack and potentially has problems (it uses autojar's
dependency resolution mechanism and therefore cannot find dynamically
added dependencies) but for us it works quite well in practice.

-Levin

Re: Including dependencies with a JAR package

Posted by dynnamitt <kj...@gmail.com>.
What you want is an uberjar ? 

try this:
https://gist.github.com/981589

regards


tommycli wrote:
> 
> I use buildr with the transitive compile.with artifact specifications.
> 
> My problem is this: After buildr makes its package, I have a nice JAR
> file, but I cannot run it without its dependency JARs.
> 
> I don't even know which JARs it depends on. How do you find out which JARs
> you need to distribute with your project? Can buildr package all of it
> into one file?
> 
> Tommy
> 

-- 
View this message in context: http://old.nabble.com/Including-dependencies-with-a-JAR-package-tp26537708p32503936.html
Sent from the Buildr - User mailing list archive at Nabble.com.