How to make a hit executable jar package can contain an extract file from an external library

Source: Internet
Author: User
Tags tidy


1. Extract the other jar packages into your classes directory and then play them together as executable jar packages.

Build.xml as follows:

<?xml version= "1.0"?>
<project name= "parser" default= "compile" basedir= "." >
<target name= "Init" >
<mkdir dir= "Bin" > </mkdir>
<mkdir dir= "Dest" > </mkdir>
</target>

<path id= "Classpath.local" >
<pathelement location= "./lib/log4j-1.2.14.jar"/>
<pathelement location= "./lib/mysql-connector-java-5.0.7-bin.jar"/>
<pathelement location= "./lib/je-3.2.43.jar"/>
<pathelement location= "./lib/nekohtml.jar"/>
<pathelement location= "./lib/tidy.jar"/>
<pathelement location= "./lib/xercesimpl.jar"/>
<pathelement location= "Bin"/>
<pathelement location= "bin/com"/>
<pathelement location= "." />
</path>

<target name= "Compile" depends= "init" >
<javac destdir= "bin" srcdir= "src" >
<classpath refid= "Classpath.local"/>
</javac>
</target>

<target name= "Run" depends= "compile" >
<java classname= "Bin/parser" classpath= "classpath.local" > </java>
</target>

<target name= "dest" depends= "compile" >
<mkdir dir= "Dest" ></mkdir>
<jar jarfile= "Dest/parser.jar" basedir= "Bin" ></jar>
</target>

<target name= "clean" >
<delete dir= "Bin" > </delete>
<delete dir= "Dest" > </delete>
</target>

<target name= "Unziplib" >
<unjar dest= "Bin" >
<fileset dir= "Lib" includes= "*.jar"/>
</unjar>
</target>

<target name= "jar" depends= "Compile,unziplib" >
<jar jarfile= "Dest/parser.jar" basedir= "Bin" >
<manifest>
<attribute name= "Main-class" value= "Com.dyoldfish.parser.Parser"/>
</manifest>
</jar>
<copy todir= "Dest" >
<fileset dir= "Doc" >
<include name= "Parser.bat"/>
<include name= "Clean.bat"/>
</fileset>
</copy>
</target>

</project>

2. Put the other Jar package library outside your executable jar package and pack
Build.xml as follows:

<?xml version= "1.0"?>
<project name= "parser" default= "compile" basedir= "." >
<target name= "Init" >
<mkdir dir= "Bin" > </mkdir>
<mkdir dir= "Dest" > </mkdir>
</target>

<path id= "Classpath.local" >
<pathelement location= "./lib/log4j-1.2.14.jar"/>
<pathelement location= "./lib/mysql-connector-java-5.0.7-bin.jar"/>
<pathelement location= "./lib/je-3.2.43.jar"/>
<pathelement location= "./lib/nekohtml.jar"/>
<pathelement location= "./lib/tidy.jar"/>
<pathelement location= "./lib/xercesimpl.jar"/>
<pathelement location= "Bin"/>
<pathelement location= "bin/com"/>
<pathelement location= "." />
</path>

<target name= "Compile" depends= "init" >
<javac destdir= "bin" srcdir= "src" >
<classpath refid= "Classpath.local"/>
<!--include name= "com/**"/-->
</javac>
<copy todir= "Bin" >
<fileset dir= "Doc" includes= "Run.bat"/>
</copy>
</target>

<target name= "Run" depends= "compile" >
<java classname= "Bin/parser" classpath= "classpath.local" > </java>
</target>

<target name= "dest" depends= "compile" >
<mkdir dir= "Dest" ></mkdir>
<jar jarfile= "Dest/parser.jar" basedir= "Bin" ></jar>
<!--copy todir= "Dest"/-->
<!--fileset dir= "bin" includes= "*.class"/-->
<!--/copy-->
</target>

<target name= "clean" >
<delete dir= "Bin" > </delete>
<delete dir= "Dest" > </delete>
</target>

<target name= "Jar" depends= "compile" >
<jar jarfile= "Dest/parser.jar" basedir= "Bin"
includes= "Com/**/*.class" >
<manifest>
<attribute name= "Main-class" value= "Com.dyoldfish.parser.Parser"/>
<attribute name= "Class-path" value= ". .. /lib/log4j-1.2.14.jar. /lib/mysql-connector-java-5.0.7-bin.jar. /lib/je-3.2.43.jar. /lib/nekohtml.jar. /lib/tidy.jar. /lib/xercesimpl.jar "/>
</manifest>
<!--fileset dir= "Lib" includes= "*.jar"/-->
</jar>
<copy todir= "Dest" >
<fileset dir= "Doc" includes= "Parser.bat"/>
</copy>
</target>

</project>

How to make a hit executable jar package can contain an extract file from an external library

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.