0

I have built a rather large java application which I would like to run as a desktop app. It has several other directories that it needs to work, along with the bin folder containing the classes, like the images folder, the 3rd party apis, like the database jar, etc. I have a build.xml that creates the jar, but the jar doesn't run. It appears to be an error with one of the apis not being found.

Here's the error:

Exception in thread "main" java.lang.NoClassDefFoundError: bibliothek/gui/dock/c
ommon/CContentArea
        at pos.main.POSsystem.<init>(Unknown Source)
        at pos.main.POSsystem.main(Unknown Source)
Caused by: java.lang.ClassNotFoundException: bibliothek.gui.dock.common.CContent
Area
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 2 more

In case you are curious about the build.xml file, here it is:

<?xml version="1.0"?>

<project name="POSsystem" default="main" basedir=".">
    <!-- Sets variables which can later be used. -->
    <!-- The value of a property is accessed via ${} -->
    <property name="src.dir" location="src" />
    <property name="build.dir" location="bin" />        <!--the default bin eclipse folder-->
    <property name="shipping.dir" location="shipping" />
    <property name="doc.dir" location="doc" />
    <property name="main-class" value="pos.main.POSsystem" />
    <property name="splash-screen" value="images/splash.png" />
    <property name = "jars.dir" value="libs" />

    <property environment="env"/>
    <property name="ECLIPSE_HOME" value="C:\eclipse"/>
    <property name="debuglevel" value="source,lines,vars"/>
    <property name="target" value="1.7"/>
    <property name="source" value="1.7"/>

    <path id= "jars.path">
        <fileset dir="${jars.dir}" includes="**/*.jar" />
    </path>


    <path id="pos.classpath">
        <pathelement location="bin"/>
        <pathelement location="${jars.dir}/docking-frames-common.jar"/>
        <pathelement location="${jars.dir}/docking-frames-core.jar"/>
        <pathelement location="${jars.dir}/hsqldb.jar"/>
    </path>

    <!--THIS IS THE ADDED CODE FOR THE CLASSPATH-->
    <pathconvert property="manifest.classpath" pathsep=" ">
      <path refid="pos.classpath"/>
      <mapper>
        <chainedmapper>
           <flattenmapper/>
           <globmapper from="*.jar" to="libs/*.jar"/>
        </chainedmapper>
      </mapper>
    </pathconvert>


    <!-- Deletes the existing build, doc and shipping directory-->
    <target name="clean">
        <echo>"Cleaning..."</echo>
        <delete dir="${build.dir}" />
        <delete dir="${shipping.dir}" />
        <delete dir="${doc.dir}" />
        <echo>"Done Cleaning..."</echo>
    </target>

    <!-- Creates the  build, doc and shipping directory-->
    <target name="makedir" depends="clean">
        <echo>"Making Directories..."</echo>
        <mkdir dir="${build.dir}" />
        <mkdir dir="${doc.dir}" />
        <mkdir dir="${shipping.dir}" />
    </target>


    <!-- Compiles the java code -->
        <target name="compile" depends="makedir"> <!--depends="doc"> CHANGE BACK WHEN YOU RE-IMPLEMENT DOC-->
            <echo>"Compiling..."</echo>
            <javac srcdir="${src.dir}" destdir="${build.dir}"  includeantruntime = "false" classpathref="jars.path" />
        </target>

    <!--Creates the deployable jar file  -->
    <target name="jar" depends="compile">
        <echo>"Making Jar..."</echo>
        <jar destfile="${shipping.dir}\POSsystem.jar" basedir="${build.dir}">
            <manifest>
                <attribute name="Built-By" value="${user.name}"/>
                <attribute name="Main-Class" value="${main-class}" />
                <attribute name="Class-Path" value="${manifest.classpath}" />
                <attribute name = "SplashScreen-Image" value="${splash-screen}" />
            </manifest>
        </jar>
    </target>

    <target name="main" depends="jar"><!--depends="run">  CHANGE BACK WHEN YOU RE-IMPLEMENT RUN-->
        <description>Main target</description>
        <echo>Main...</echo>

        <!--run it here for now instead of from the jar-->
        <java classname="pos.main.POSsystem" failonerror="true" fork="yes">
            <jvmarg line="-splash:images/splash.png"/>
            <classpath refid="pos.classpath"/>
        </java>

    </target>

</project>

If I run the build.xml as an ant build it all compiles and via the build will run the application as well, but the jar won't.

If I'm missing any helpful information, please let me know. I've read plenty of tutorials on creating a desktop application with java, but can't seem to get this right.

UPDATE/EDIT Via the comment below by Jayan, I figure my problem is indeed not including the correct classpath. So I've updated my build.xml file to include a path convert property and added the attribute class-path to the jar target. However, I still get the same exact error as posted above.

Matt
  • 5,408
  • 14
  • 52
  • 79
  • You should set 'Class-Path' attribute. – Jayan Jan 21 '13 at 16:41
  • http://stackoverflow.com/questions/858766/generate-manifest-class-path-from-classpath-in-ant – Jayan Jan 21 '13 at 16:44
  • Thanks Jayan. I've edited my post to reflect the added class-path attribute, but I'm still getting the same error. – Matt Jan 21 '13 at 17:40
  • As it turns out, the problem here was caused by a defective developer release of JAR files for the Docking Frames API. After I downloaded the most recent version of the JARS I was able to create the deployable JAR. – Matt Jan 21 '13 at 23:11
  • @ Matt8541: Good to know. You may write down something about how defective jar was identified. You can accept your own answer. – Jayan Jan 22 '13 at 01:20

0 Answers0