0

I need to include some third party jar file to my project jar. I mentioned it in my build.xml and include this to MANIFEST.MF. Now i get thirdparty1.jar thirdparty2.jar file into inside the project jar. But still i can't able to use the jars. Is it need any addition configuration

Here is my build.xml

<manifest>          
    <attribute name="Class-Path" value="thirdparty1.jar thirdparty2.jar thirdparty3.jar"/>

If i copy the two jar separately it works well. But i don't understand what is the need for copy these separate. How it solve with out copying jar separately.

Arun M R Nair
  • 653
  • 7
  • 30

2 Answers2

1

If the dependency jar is packaged inside the project jar, you need a solution to load it from there. The standard class-path handling in Java won't access jar files located inside other jar files.

See this answer: Classpath including JAR within a JAR. Specifically the One Jar solution: http://one-jar.sourceforge.net/.

Community
  • 1
  • 1
ash
  • 4,867
  • 1
  • 23
  • 33
0

It's also possible to use zipgroupfileset for that.given is the sample ant task for that.

<!-- Build JAR file  -->
<target name="jar" depends="init-build-dir,compile-main">
<!--creating a temp jar contains all jar -->
    <jar jarfile="${project.build.lib.dir}/external-libs.jar">
        <zipgroupfileset dir="${project.lib.redist.dir}">
            <include name="**/*.jar" />
        </zipgroupfileset>
    </jar>
    <sleep seconds="1" />
    <!-- creating main jar with temp jar-->
    <jar jarfile="${project.build.lib.dir}/${ant.project.name}.jar" manifest="MANIFEST.MF">
        <fileset dir="${project.build.main.classes.dir}" includes="**/*.*" />
        <zipfileset src="${project.build.lib.dir}/external-libs.jar">
            <exclude name="*" />
        </zipfileset>
    </jar>
   <!--removing temp jar -->
    <delete>
        <fileset dir="${project.build.lib.dir}">
            <include name="external-libs.jar" />
        </fileset>
    </delete>
</target>
Arun M R Nair
  • 653
  • 7
  • 30