0

I have the following for building my jar currently:

 <jar jarfile="${bin.dir}/${name}.jar" basedir="${build.src.dir}">
            <zipfileset src="${bin.lib.dir}/dependencies-compact.jar"
                        excludes="META-INF/*.SF" />
  </jar>

But this makes everything jumbled inside the jar. The plan now is inside the jar, there will be a folder called lib, and the MANIFEST.MF's classpath variable will be updated with the list of all the jars in lib folder. How to achieve this on ant?

lorraine batol
  • 6,001
  • 16
  • 55
  • 114

1 Answers1

0

The classpath in the Manifest refers to external jars, not classes that you have pulled inside your jar file.

The following is a sample of how I use ivy to put my jar's dependencies into an adjacent "lib" directory and then use the ANT manifestclasspath task to construct the string that goes into the jar manifest:

  <target name="build" depends="compile">
    <ivy:retrieve pattern="${dist.dir}/lib/[artifact].[ext]"/>

    <manifestclasspath property="jar.classpath" jarfile="${dist.jar}">
      <classpath>
        <fileset dir="${dist.dir}/lib" includes="*.jar"/>
      </classpath>
    </manifestclasspath>

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

For more detailed examples that include ivy files and unit tests see:

Community
  • 1
  • 1
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185