I would like to unjar multiple JAR files and then rebuild into one JAR using an ant build script. Is this possible?
相关问题
- Dependencies while implementing Mocking in Junit4
- Unable to generate jar file for Hadoop
- Using task scheduler for running java jar (from ba
- NIO2: how to generically map a URI to a Path?
- How can I have my ant task pass or fail based on t
相关文章
- java.lang.NoClassDefFoundError: javax/servlet/http
- Default arguments in JAR-manifest
- Passing command line arguments to Java via ant bui
- ANT - Could not load a dependent class com/jcraft/
- intellij build jar artifact containing gradle depe
- library resolve to a path with no project.properti
- ant file that depends on another ant file
- android-sdk/tools/ant/build.xml:698: null returned
Yes, it's possible with ant. A jar file is basically a zip with a special manifest file. So to unjar, we need to unzip the jars. Ant includes an unzip task.
To unzip/unjar all the jar files in your project:
Obviously you need to declare ${build.dir} and ${lib.dir} first. The line
<include name="**/*.jar" />
tells ant to include all files that end up with the jar extension, you can tweak that include to suit your needs.To pack everything into a jar, you use the jar task:
In this example, we include different filesets. In one fileset we are including all compiled classes. In another fileset we include two config files that this particular project depends upon.
There is also a project devoted to repackage jars called JarJar. You can use it to repackage mutiple Jars into one. Depending on your requirements, you can even rename classes to prevent version conflicts.
From their getting started page:
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):
Yes it is !
You have two possibilities :
This is useful if you don't need to exclude content that are in some jars (like for example some properties configuration file that might override yours, etc). Here the excludes properties is filtering out files from the dir property.
The other solution is to use the zipfileset tag where the excludes property this time will filter out content from the jar to be merged.
Yes, it's possible.
One possible solution that creates one jar file from all the jar files in a given directory: