0

I have craated a Java application with an Ant build file containing the jar-task task that generate a jar file from the application.

<target name="jar-task" depends="compile">
    <mkdir dir="${jar.dir}"/>
    <jar destfile="jar/guix.jar" basedir="${bin.dir}">
        <fileset dir="${basedir}">
            <include name="${basedir}/images/**/" />
            </fileset>
            <manifest>
                <attribute name="Main-Class" value="IO.Deep.clk.GUI"/>
                <attribute name="Class-Path" value="${basedir}/SPLASH-2.0.0.jar ${basedir}/lib/dist/* ${basedir}/user.properties"/>
            </manifest>
        <filelist dir="${basedir}" files="user.properties"/>
    </jar>
</target>

When I execute on the command line however a NoClassDefFoundError stating

Could not find the main class IO.Deep.clk.GUI. Program will exit.

Now, the GUI file is exactly in the specific folder and in the same package, I really can't understand where the error may be...can anyone help?

Anto
  • 4,265
  • 14
  • 63
  • 113

2 Answers2

1

The name images suggests, that the jar file will contain only images. But where is the actual code?

    <fileset dir="${basedir}">
        <include name="${basedir}/images/**/" />
    </fileset>

This piece

    <attribute name="Class-Path" value="${basedir}/SPLASH-2.0.0.jar ${basedir}/lib/dist/* ${basedir}/user.properties"/>

will write full qualified pathnames into the manifest. Are sure, that this is correct? Also note, that the code will not find user.properties by putting the file on the classpath. The classpath can contain only directories or jar-files in which classes or other stuff will be searched for. But simple files won't work.

I'm also not sure about the lib/* part. Is the class IO.Deep.clk.GUI in one of the jar files in that directory? That would be a hint, that all directories must be listed explicitly. If that's not a problem - good.

EDIT: The classpath problems can be avoided by adding the task manifestclasspath (Ant docs) before the call of jar and by using the generated classpath value inside the manifest attribute. Outline:

    <manifestclasspath property="jar.class.path" jarfile="jar/guix.jar">
        <classpath>
            <fileset dir="." includes="*.jar" />
            <fileset dir="." includes="lib/*.jar" />
        </classpath>
    </manifestclasspath>
    <echo message="Class-Path will be: ${jar.class.path}" />
    <jar ....>
        ....
        <attribute name="Class-Path" value="${jar.class.path}" />
A.H.
  • 63,967
  • 15
  • 92
  • 126
0

Are you sure your resulting filest inside the jar task contains all the files you need?

For debugging you can use a path convert to the fileset out of the jar task and echo it so that you can verfiy that you have the correct files. If this is OK then I don't see something else wrong in your file although I have limited experience with the jar task myself.

FailedDev
  • 26,680
  • 9
  • 53
  • 73