简体   繁体   中英

how to combine jar files from dist folder and jar files in lib within dist folder to make a single jar file using build.xml

How does one combine jar files from dist folder and jar files in lib within dist folder to make a single jar file using build.xml . Currently I use the following code to make single jar, but it will show the message "A java exception has occurred".

.

<?xml version="1.0" encoding="UTF-8"?>  
<project name="CIH_Billing" default="jar">  
<target name="jar">
<zip destfile="output.jar"> 
     <zipgroupfileset dir="dist/lib" includes="*.jar"/>
     <zipgroupfileset dir="dist" includes="*.jar"/>
</zip>  
</target>
</project>

You don't. Valid JAR files cannot contain other JAR files. If you really, really want to do this there are ways, but you need to think long and hard about the reasons for justifying this. Using something like Jar Jar Links for instance, while raising other issues does do what you want. Alternatively, you can extract all the jars and combine them manually, which also has it's drawbacks.

However as a general rule of thumb java applications are distributed as a bundle and launched with a small batch script (which sets the classpath and launches the main method). If you don't want to do it this way, but want a standalone jar, there is always Jar Jar Links , if you want a stand alone Windows binary. you can always use something like Excelsior JET or Avian .

Using either with Ant though was somewhat complicated last time I checked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM