在build.xml中指定一个外部jar,以便在编译后添加到生成的jar中

时间:2013-02-11 20:19:02

标签: java ant jar build.xml

我正在尝试修改build.xml文件,以指定要添加到最终编译jar的外部jar。

这是我的build.xml文件

  <project name="cmmdcservice" default="all">
  <property name="kf.dir" location="E:\knopflerfish_osgi_3.4.0"/>
  <property name="framework.jar"
   location="${kf.dir}/osgi/framework.jar"/>

  <target name="all" depends="init,compile,jar"/>

  <target name="init">
  <mkdir dir="out/classes"/>
  </target>

  <target name="compile">
  <javac destdir = "out/classes"
  debug = "on"
  srcdir = "src"
  includeantruntime="false">
  <classpath>
    <pathelement location="${framework.jar}"/>
  </classpath>
  </javac>
  </target>

  <target name="jar">
  <jar basedir = "out/classes"
  jarfile = "out/${ant.project.name}.jar"
  compress = "true"
  includes = "**/*"
  manifest = "manifest.mf"/>
  </target>

  <target name="clean">
  <delete dir = "out"/>
  </target>
  </project>

我想在某种程度上在目标名称=“jar”部分我需要引用我的外部jar,但实际上并不知道如何...任何想法?

1 个答案:

答案 0 :(得分:1)

您需要添加一个post-jar部分。这是一个例子:

<target name="-post-jar">
  <jar update="true" destfile="${dist.jar}">
    <!-- Path to your jar. -->
    <zipfileset src="/home/user/javalibs/myjar.jar"/>
 </jar>
</target>