tags:

views:

720

answers:

2

I have begun working on a project that, at the moment, produces a monolithic JAR file from an Eclipse project. Basically, there is an Ant script that runs anytime the Eclipse Java Builder runs and takes the output of the Eclipse Java Builder (the .class files) and packages that up into a JAR file. That JAR file is then placed in a common directory so other tools can grab it for the latest build.

This works well for the team so I don't want to change it too much, but, there are a lot of unnecessary files within that JAR making it much larger than it needs to be. I was wondering if it was possible, within the same sort of framework as I described above (Eclipse + Ant), to split up the big JAR file into smaller, more manageable JAR files. For example:

com.company.project.thing1 com.company.project.thing2 com.company.project.thing3

All three things are packaged into the JAR. Instead, I only want thing1 and thing2 in one JAR file and thing3 to be in a second JAR file.

I do realize I could have separate projects, but I wanted to see if it was possible to keep the project grouped together still as that does make sense. Any help would be much appreciated.

Thank you.

Per request, the Ant Build Script (I only included the jar task - the other is just a clean):

<target name="jar" description="Deploys the JAR file." depends="clean">
    <mkdir dir="${dir.dist}">

    <!-- Build the JAR file containing the classes. -->
    <jar destfile="${dir.dist}/${build.name}.jar">

        <!-- Generate the MANIFEST.MF file. -->
       <manifest>
           <attribute name="Built-By" value="${user.name}" />
           <attribute name="Release-Version" value=${version}" />
       </manifest>

       <zipfileset dir="${dir.build}" />
   </jar>
</target>
A: 

Hi there!

Can you paste the content of your build.xml file (the one used by Ant) ?

It's very simpla what you have to do, but show us the build file so we can help you.

OR.. read by yourself on Ant jar task

Flueras Bogdan
I added it. I do understand the JAR task, but I'm not sure I understand how to use it in context of knowing how to pull out specific parts of the Eclipse build. That's what is giving me some difficulty.
JasCav
+1  A: 

if you use the includes facility of the zipfileset (and some macrodef magic), you could end up with something like the following:

<macrodef name="packaging">
    <attribute name="package"/>
    <sequential>
        <jar destfile="${dir.dist}/${build.name}-@{package}.jar">
            <manifest>
                <attribute name="Built-By" value="${user.name}"/>
                <attribute name="Release-Version" value=${version}"/>
            </manifest>

            <zipfileset dir="${dir.build}" includes="com/acme/@{package}/**/>
        </jar>
    </sequential>
</macrodef>

<packaging package="package1"/>
<packaging package="package2"/>
<packaging package="package3"/>
Vladimir
This is perfect, thank you! I did not know about macrodef - thank you for showing me that as well (+1).
JasCav