如何让打的可执行jar包可以包含外部库的解压文件
Posted 君临裙下
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何让打的可执行jar包可以包含外部库的解压文件相关的知识,希望对你有一定的参考价值。
1、把别的jar包库,解压到你的classes目录下面,然后一起打成可执行jar包
build.xml 如下:
<?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、把别的jar包库,放在你的可执行jar包外面,然后打包
build.xml如下:
<?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>
以上是关于如何让打的可执行jar包可以包含外部库的解压文件的主要内容,如果未能解决你的问题,请参考以下文章