Executable Jar Question

Greetings all.  I have seen a few "Executable Jar" threads in the past, thought I might add one myself.



Background:  I checked out JME into Eclipse using the standard tutorial.  Directory structure is normal – src/ contains .java files, bin/ contains .class files, lib/ contains .jar files.



I am using an ant script to build an executable .jar:


<?xml version="1.0" encoding="UTF-8"?>

<!-- Execute .jar by doing:    java -Djava.library.path=./lib/ -jar buildjar.jar     -->

<project name="SAGE" default="SAGEmain" basedir=".">
   
    <target name="SAGEmain">
      <jar destfile="buildjar.jar">
        <fileset dir="">
          <include name="**/*.class"/>
          <include name="resources/**/*"/>
          <include name="bin/**/*"/>
          <include name="lib/**/*"/>
        </fileset>
        <manifest>
           <attribute name="Main-Class" value="cave.CLASSManager"/>
           <attribute name="Class-Path" value=". ./lib/FengGUI.jar ./lib/hsqldb.jar ./lib/jinput.jar ./lib/jogg-0.0.7.jar ./lib/jorbis-0.0.15.jar ./lib/junit-4.1.jar ./lib/lwjgl.jar ./lib/lwjgl_util_applet.jar"/>
        </manifest>
      </jar>
    </target>
   
</project>



When I try running it, using java -Djava.library.path=./lib/ -jar buildjar.jar, I receive:

Exception in thread "main" java.lang.NoClassDefFoundError: cave/CLASSManager

However, I define the Main-Class, unpacking the .jar shows that it exists in   bin/cave/CLASSManager.class.

Any ideas?  Thanks in advance :).

doesn't the class dirs need to be in the top of the jar, not in some bin dir?

This is my first time using Ant, so I'm not sure – I do know that changing the Main-Class to something like bin/cave.CLASSManager did not work.



To try your method, I'd just copy everything in   bin/   to my root folder?  Will try now.





Edit:  Thank you very much!  That works splendidly.



Seeing that you are an admin here – I'm not trying to be a one-post newb on the forums.  I'll start trying to help others as penance for requiring your help :).

Uhhh… hmmm… mine doesn't seem to work. I get:


Exception in thread "main" java.lang.NoClassDefFoundError: Euphrates (wrong name: jmetest/ARK/Euphrates)
        at java.lang.ClassLoader.defineClass1(Native Method)
        ...
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)



Which seems better than the alternative that I get when I type something that I know is wrong...

Exception in thread "main" java.lang.NoClassDefFoundError: Euphrates.bunny



All of my class files are at the top of the jar when you open it... including Euphrates.class... the item that it can't find.

Any ideas?

EDIT:  As suggested in another post, dumping the lib folder into the dir you are working out of fixes that problem...
I'm so close to being able to send my game demo to my friends... yet so far away... The jar finally works but all path references fail for the classes inside :(

I'm sure there is a simple solution but it seems that no one else is having this problem...
How do you set the working directory to be the jar itself???
I figured that would be the default but it isn't working
"jar/jmetest/data/images/Poster_Draft.png"
"./jmetest/data/images/Poster_Draft.png"
"/jmetest/data/images/Poster_Draft.png"
"jmetest/data/images/Poster_Draft.png"
None of these work and I've already checked inside the jar file and confirmed that it is there...

Can I do it from the ant build script?  None of the setting working directory commands that I found online worked...