Arun M R Nair
Arun M R Nair

Reputation: 653

How to include library files while creating jar files without copying library separately

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.

Upvotes: 0

Views: 188

Answers (2)

Arun M R Nair
Arun M R Nair

Reputation: 653

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>

Upvotes: 0

ash
ash

Reputation: 5155

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/.

Upvotes: 1

Related Questions