views:

619

answers:

3

I'm having trouble using jarjar from the command-line to combine a simple Scala program with the scala runtime-library.

jarjar correctly detects the dependency:

$ java -jar ~/Desktop/saug/jarjar-1.0.jar find jar BCT.jar scala-library.jar
/home/schani/Work/scala/bct/BCT.jar -> /home/schani/Work/scala/bct/scala-library.jar

Combining them doesn't work, however:

$ CLASSPATH=./scala-library.jar java -jar ~/Desktop/saug/jarjar-1.0.jar process rules.jjl BCT.jar BCTS.jar

The jar file that I get still depends on scala-library.jar. Whether or not I add the CLASSPATH variable makes no difference. My rules.jjl file looks like this:

keep BCT

What to do?

+1  A: 

Using the java "-jar" option ignores the classpath. Try specifying the main class explicitly with a classpath, and omit "-jar":

java -cp ~/Desktop/saug/jarjar-1.0.jar:./scala-library.jar com.tonicsystems.jarjar.Main process rules.jjl BCT.jar BCTS.jar
vdichev
Doesn't work, either.
Mark Probst
A: 

Try adding a keep for the scala.runtime.Nothing$ class. I found this necessary when using a similar product (autojar; http://autojar.sourceforge.net/en%5Fd/index.html) with Scala.

scaling_out
That doesn't work, either. jarjar seems to only take classes from the input jar file specified on the command line, but not from any dependent jars, and there doesn't seem to be a way to specify them.
Mark Probst
A: 

jarjar does not repackage other jars into your jar. It only renames dependencies inside the one jar itself.

Use the method outlined here http://stackoverflow.com/questions/515428/clean-way-to-combine-multiple-jars-preferably-using-ant to rejar all the dependent jars into your jar, then run jarjar to prevent future dependency hell.

yincrash
actually, just rezipping using the ant task is not the most ideal solution. i used the eclipse fat-jar plugin to do this. basically, make an empty project and put all the jars in the build path of the project then use the fat-jar plugin http://fjep.sourceforge.net/ to export to a fat jar.
yincrash