GettingStarted
In which we cover what most people care about.
Featured In our imaginary project, the Ant "jar" target looks like: <target name="jar" depends="compile"> <jar jarfile="dist/example.jar"> <fileset dir="build/main"/> </jar> </target> To use Jar Jar Links, we define a new task named "jarjar", and substitute it wherever we used the jar task. Because the JarJarTask class extends the normal Ant Jar task, you can use jarjar without any of its additional features, if you want: <target name="jar" depends="compile"> <taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpath="lib/jarjar.jar"/> <jarjar jarfile="dist/example.jar"> <fileset dir="build/main"/> </jarjar> </target> Just like with the "jar" task, we can include the contents of another jar file using the "zipfileset" element. But simply including another projects classes is not good enough to avoid jar hell, since the class names remain unchanged and can still conflict with other versions. To rename the classes, JarJarTask adds a new "rule" element. The rule takes a "pattern" attribute, which uses wildcards to match against class names, and a "result" attribute, which describes how to transform the matched names. In this example we include classes from jaxen.jar and add a rule that changes any class name starting with "org.jaxen" to start with "org.example.jaxen" instead (in our imaginary world we control the example.org domain): <target name="jar" depends="compile"> <taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpath="lib/jarjar.jar"/> <jarjar jarfile="dist/example.jar"> <fileset dir="build/main"/> <zipfileset src="lib/jaxen.jar"/> <rule pattern="org.jaxen.**" result="org.example.@1"/> </jarjar> </target> The ** in the pattern means to match against any valid package substring. To match against a single package component (by excluding dots (.) from the match), a single * may be used instead. The @1 in the result is a reference to the ** portion of the rule. For every * or ** in the rule, a numbered reference is available for use in the result. References are numbered from left to right, starting with @1, then @2, and so on. The special @0 reference refers to the entire class name. |
can you write a sample of calling it from the command line without ant?
Suppose I have a directory 'lib' with all the dependencies of my project, and I want to ship a single jar file with my classes and the dependencies.
How do I make a jarjar target that includes my class files under build/classes, and the contents of the jar files under lib/ ?
leonel.gayard,
Yea, I want what Leonel wants. In the wiki example, would all we have to do is just NOT include the rule tag.
I just want to include multiple jars into one large jar file.
thanks for the tool, this will fix a lot of problems.
No repsonses on here for a while... Just wondering if there's any info on being able to do what the last 2 posters requested. Thanks!
You can replace the zipfileset with:
That seems to do the job...
It is not renaming packages within text files. Is there any way to tell jarjar to process resource files?
Using zipgroupfileset with dir="lib" and includes=".jar" does not do what listing each of the jars as in the example using the src attribute does. The difference is, when trying to include multiple jars in this way the jars aren't unrolled and you end up with jars at the root of the jar created by jarjar. Unless I am doing something wrong, it would be really cool if this could be done using regex style includes.
Do you know if this is allowed by the Apache license? Is Apache Software Foundation okay with me jarjar-ing one of their libs to include in my software, as long as I include their original license text?
Captain Tarpals: Hey, you-sa! Stop-pa dere! Jar-Jar Binks: Hey yo, Daddy, Captain Tarpals. Mesa back. Captain Tarpals: No-ah 'gain, Jar Jar. You-sa goin' to da Bosses. You-sa in big doo-doo dis time! Jar gets shocked by a Gungan spear? Jar-Jar Binks: Yipe! How wude!
<zipgroupfileset dir="lib" includes="*.jar" /> did work for me!
Hello guys, can this Jar be used to merge two jar files (a.jar and b.jar) into one jar file? What is the syntax please? Thanks
I am getting this error... taskdef class com.tonicsystems.jarjar.JarJarTask? cannot be found
my jarjar.jar and other jar files are under referenced libraries.I am using eclipse
java -jar jarjar-1.2.jar find jar hibernate3.jar . No response after running the command .. Am i doing anything wrong ??
Error reading org/apache/catalina/connector/OutputBuffer?.class: ClassReader?.accept() should be called with EXPAND_FRAMES flag
Got the following error ?
Please update the usage and change log of jarjar 1.4, thanks a lot.
I do something wrong? I get this message:
$ java -jar jarjar-1.4.jar Failed to load Main-Class manifest attribute from jarjar-1.4.jar
I've put together an article about work-around to solve this issue here: http://priyanka-tyagi.blogspot.com/2013/03/dealing-with-java-hell-using-jarjar.html
I think Java programmers cannot tell the difference between the commandline and ant files.
dude if you went to so much trouble, can you please give steps of how to use it. I get the error com.tonicsystems.jarjar.JarJarTask? cannot be found
Obviously, I need to add this jar somewhere so Ant can find it. But why not include the steps in your tutorial? I mean this is probably causing 90% of the people to abandon it straightaway.