Creating multiple JARs from an Eclipse project

I started work on a project that is currently creating a monolithic JAR file from an Eclipse project. Basically, there is an Ant script that runs anytime Java Builder Eclipse starts up and prints Java Builder Eclipse output (.class files) and packages that are in the JAR file. This JAR file is then placed in a shared directory so other tools can capture 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 in this JAR file, which makes it much more than necessary. I was wondering if it is possible in the same structure as I described above (Eclipse + Ant) to split a large JAR file into smaller, more manageable JAR files. For instance:

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

All three things are packed in a JAR. Instead, I want thing1 and thing2 in the same JAR file and thing3 to be in the second JAR file.

I understand that I can have separate projects, but I wanted to see if I managed to save the project together, because it makes sense. Any help would be greatly appreciated.

Thanks.

At the request of the Ant Build script (I only included the jar task - the other is just 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> 
+4
source share
2 answers

if you use the includes tool in the zipfileset (and some macrodef magic), you can get 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"/> 
+3
source

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

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

OR .. read yourself Ant task jar

0
source

All Articles