Question

I would like to know how to run JarJar with Ant, passing the rules in with an external Rules file.


1) I know I can pass the rules in one by one as below:

    <jarjar destfile="B.jar" >
        <zipfileset src="A.jar" />

        <rule pattern="com.a.**" result="test.b.@1" />
    </jarjar>

2) I know I can pass the rules in a file if I run it from the command line:

    java -jar jarjar.jar process <rulesFile> <inJar> <outJar>

3) I can use the above command line in an Ant <exec> task. (best workaround)

4) I found some reference to using a <rulesFile> tag in Maven.


The above options are not ideal for what I would like to do.

I want to run JarJar from an Ant task, passing in a rules file.

Was it helpful?

Solution

I have been unable to get any information about this, from any forum, or by mailing the developers of JarJar, so I have decided to answer this question with a workaround that I am using:

As an example, the below build.xml file includes the contents of another test.txt file inline. I import the text file using the tag include_this (this is my name - you can use any name here):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE project [
    <!ENTITY include_this SYSTEM "test.txt">
]>

<project name="Test" default="build" >

    <target name="build" >
        &include_this;
    </target>

</project>

In this simple example, the contents of the test.txt file is:

<echo>This is a test.</echo>

So I've been using this workaround to replace the rules in the jarjar call. Putting the rules in the test.txt file:

<rule pattern="com.**" result="${project.output}.com.@1" />
<rule pattern="org.**" result="${project.output}.org.@1" />

My jarjar call then becomes:

<!-- jarjar uses the same syntax as the jar task -->
<jarjar destfile="${jarjar.output.dir}/${project.output}.jar" >
    <!-- source files -->
    <zipfileset src="${jar.output.dir}/${project.output}.jar" />

    <!-- refactoring rules -->
    &include_this;
</jarjar>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top