通过Ant创建jar后,不包含Classpath jar(ojdbc6.jar)

时间:2015-07-22 09:58:32

标签: java ant

我能够使用manifest.mf生成一个jar文件。但是,当我在命令提示符下运行jar文件时,它会查找oracle驱动程序。我很确定我已经在eclipse项目构建路径中添加了这个。

我的build.xml:

<?xml version="1.0"?>
<project name="converter" default="main" basedir=".">
   <property name="projectName" value="Converter" />
   <property name="src.dir" value="src"/>
   <property name="web.dir" value="war"/>
   <property name="lib.dir" value="lib"/>
   <property name="dist.dir" location="dist" />
   <property name="dist.lib.dir" location="dist/lib" />
   <property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
   <property name="name" value="converter"/>
   <property name="main-class" value="com.ouc.mv90.conversion.CSVtoMV90Converter" />

   <target name="init">
        <mkdir dir="${build.dir}" />
    </target>

   <!-- external libraries classpath, we don't need sources and javadoc -->
   <path id="classpath">
        <fileset dir="${basedir}/">
            <include name="${lib.dir}/*.jar" />
            <exclude name="${lib.dir}/*sources.jar"/>
            <exclude name="${lib.dir}/*javadoc.jar"/>
        </fileset>
    </path>

    <!-- To work with external libraries, need classpath to compile -->
    <target name="compile" depends="init" description="compile the source ">
        <javac includeantruntime="false" srcdir="${src.dir}" destdir="${build.dir}" classpathref="classpath" />
    </target>

    <!-- constructs the external libraries classpath name -->
    <pathconvert property="classpath.name" pathsep=" ">
        <path refid="classpath" />
        <mapper>
            <chainedmapper>
                <flattenmapper />
                <globmapper from="*.jar" to="lib/*.jar" />
            </chainedmapper>
        </mapper>
    </pathconvert>

    <target name="copy-dependencies">
        <copy todir="${dist.lib.dir}">
            <fileset dir="${lib.dir}" includes="**/*.jar" excludes="**/*sources.jar, **/*javadoc.jar" />
        </copy>
    </target>

    <!-- jar it, and declares the ext libraries in manifest.mf file -->
    <target name="jar" depends="compile, copy-dependencies" description="package, output to JAR">

        <echo message="classpath.name : ${classpath.name} " />

        <mkdir dir="${dist.dir}" />
        <mkdir dir="${dist.lib.dir}" />

        <jar jarfile="${dist.dir}/${projectName}.jar" basedir="${build.dir}">
            <manifest>
                <attribute name="Main-Class" value="${main-class}" />
                <attribute name="Class-Path" value="${classpath.name}" />
            </manifest>
        </jar>
    </target>

    <target name="clean" description="clean up">
        <delete dir="${build.dir}" />
        <delete dir="${dist.dir}" />
    </target>

   <!-- Default, run this -->
        <target name="main" depends="clean, compile, jar" />
</project>

MANIFEST.MF

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.6.0_43-b01 (Sun Microsystems Inc.)
Main-Class: com.ouc.mv90.conversion.CSVtoMV90Converter
Class-Path: lib/ojdbc6.jar

0 个答案:

没有答案