具有内部依赖性的Ant

时间:2013-07-15 19:30:16

标签: ant

我现在有一个使用外部依赖项的jar。我正在尝试创建一个包装内部所有外部依赖项的jar,并且只给我一个jar。我多次看到这个问题,但我仍然无法弄明白。我正在使用Ant,并复制了我在这里看到的一些例子。我正在使用zipgroupfileset来引用外部(现在是内部)jar。一旦我添加了zipgroupfileset,我就遇到了一个运行时错误,说我的Runner类无法找到。

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
              Any modifications will be overwritten.
              To include a user specific buildfile here, simply create one in the same
              directory with the processing instruction <?eclipse.ant.import?>
              as the first entry and export the buildfile again. -->
<project basedir="." default="build" name="ExcelDemo">
    <property environment="env"/>
    <property name="ECLIPSE_HOME" value="../../../../Program Files (x86)/eclipse"/>
    <property name="debuglevel" value="source,lines,vars"/>
    <property name="target" value="1.6"/>
    <property name="source" value="1.6"/>
    <property name="external-lib-dir" value="lib\poi-3.9" />
    <property name="external-lib-dir2" value="lib\poi-3.9\lib" />
    <property name="external-lib-dir3" value="lib\poi-3.9\ooxml-lib" />
    <path id="ExcelDemo.classpath">
        <pathelement location="bin"/>
    </path>
    <target name="init">
        <mkdir dir="bin"/>
        <copy includeemptydirs="false" todir="bin">
            <fileset dir="src" excludes="**/*.launch, **/*.java"/>
        </copy>
    </target>
    <target name="clean">
        <delete dir="bin"/>
    </target>
    <target depends="clean" name="cleanall"/>
    <target depends="build-subprojects,build-project" name="build"/>
    <target name="build-subprojects"/>
    <target depends="init" name="build-project">
        <echo message="${ant.project.name}: ${ant.file}"/>
        <javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
            <src path="src"/>
            <classpath refid="ExcelDemo.classpath"/>
        </javac>
    </target>
    <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects">
        <ant antfile="${ExcelSensitize.location}/build.xml" inheritAll="false" target="clean"/>
        <ant antfile="${ExcelSensitize.location}/build.xml" inheritAll="false" target="build">
            <propertyset>
                <propertyref name="build.compiler"/>
            </propertyset>
        </ant>
    </target>
    <target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
        <copy todir="${ant.library.dir}">
            <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
        </copy>
        <unzip dest="${ant.library.dir}">
            <patternset includes="jdtCompilerAdapter.jar"/>
            <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
        </unzip>
    </target>
    <target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
        <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
        <antcall target="build"/>
    </target>
    <target name="RunnerClass">
        <java classname="runner.RunnerClass" failonerror="true" fork="yes">
            <classpath refid="ExcelDemo.classpath"/>
        </java>
    </target>
    <target name="jar" description="Create a jar for this project">
        <manifestclasspath property="lib.list" jarfile="Test.jar">
            <classpath refid="ExcelDemo.classpath" /> 
        </manifestclasspath>
        <jar jarfile="Test.jar" includes="*.class" basedir="bin">
            <zipgroupfileset dir="${external-lib-dir}" includes="*.jar"/>
            <zipgroupfileset dir="${external-lib-dir2}" includes="*.jar"/>
            <zipgroupfileset dir="${external-lib-dir3}" includes="*.jar"/>
            <manifest>
                <attribute name="Class-Path" value="${lib.list}" /> 
                <attribute name="Main-Class" value="runner.RunnerClass" /> 
            </manifest>
        </jar>
    </target>
</project>

2 个答案:

答案 0 :(得分:1)

简化事情:

  • 创建单独的 sources jar 进行编译。然后,有一个没有源的单独的编译jar。
  • 不包括第三方罐子。相反,请使用Ivy with Ant。 Ant将自动下载所需的jar。事实上,我看到只包含ivy.jar的来源,因此当你解开来源时会自动配置常春藤。您键入ant,所有内容都只是构建。

作为替代方案,您可以查看Maven,即现在打包的项目数量。实际上,如果您的jar是一个开源项目,您可以将其托管在OSS Maven存储库中。这样,甚至没有人需要手动下载你编译的jar。如果他们想要它,他们会配置他们的Maven项目为他们做。

答案 1 :(得分:0)

我认为问题是你在jar任务中使用basedir =“bin”。然后你的zipgroupfileset的路径转换为bin / $ {external-lib-dir}