码迷,mamicode.com
首页 > 编程语言 > 详细

如何让打的可执行jar包可以包含外部库的解压文件

时间:2018-04-20 11:43:56      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:depend   local   default   sql   mkdir   location   --   build   build.xml   


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包可以包含外部库的解压文件

标签:depend   local   default   sql   mkdir   location   --   build   build.xml   

原文地址:https://www.cnblogs.com/junlinqunxia/p/8889226.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!