Question

I am creating jar via eclipse, but not runnable jar, it is just a library. After importing that i'm creating new project and adding this jar file. But when run application it throws exception about not finding libraries which are inside in my jar. But these libraries are included in created jar. Where is my mistake ? How can I do that ?

Was it helpful?

Solution 2

I found the solution. I write some ant script for creating jar and it was solved my problem.

<target name="dist" depends="build-jar">


    <property name="store.jar.name" value="MYJARNAME"/>

    <property name="store.dir" value="store"/>
    <property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>

    <echo message="Packaging project into a single JAR at ${store.jar}"/>

    <mkdir dir="dist"/>
    <delete dir="${store.dir}"/>
    <mkdir dir="${store.dir}"/>
    <mkdir dir="dist/lib"/>
    <copy todir="dist/lib/" overwrite="false" granularity="9223372036854">
        <fileset dir="lib/"/>
    </copy>
    <jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
        <zipgroupfileset dir="dist" includes="*.jar"/>
        <zipgroupfileset dir="dist/lib" includes="*.jar"/>

        <manifest>
            <attribute name="Main-Class" value="${main.class}"/>
        </manifest>
    </jar>

    <zip destfile="${store.jar}">
        <zipfileset src="${store.dir}/temp_final.jar"
        excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
    </zip>

    <delete file="${store.dir}/temp_final.jar"/>

</target>

OTHER TIPS

You cannot, by default, include dependency JAR files inside your JAR file, you need a plugin, as specified in Classpath including JAR within a JAR (suggested by Artur Malinowski). If, however, you wish to create a JAR which simply works with your other dependencies, you can easily do this via Eclipse by right clicking on the project, going into properties, Java Build Path, Libraries and then you can add JARs, etc. by using the buttons along the right side of the menu (as of Kepler).

I hope this helps.

P.S. You'll have to cart round the dependency JAR files wherever you put the main JAR, however, this is the easiest and most straightforward approach to getting it working in the first place, and then refine later, using build plugins.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top