I'm having an issue similar to ones like:
http://www.jmonkeyengine.com/jmeforum/index.php?topic=6183.0
http://www.jmonkeyengine.com/jmeforum/index.php?topic=4193.0
But my case is a little different.
Things run fine if I use the Run through the Run Dialog because that has all the sources on the classpath. But that's not the way I need it to work. I'm not going to be compiling the sources of jME into my game, I want to have the library included through classpath. But I want it to work through the Class-Path in the Manifest file, not through arguments passed through the command to run.
So I haven't been using the built in stuff to build, but I have a Ant file instead I'm using. Part of what it does is take all the jME and jME-Physics jar files, and their dependencies and copies them to the out/lib directory. Then it uses that to create a classpath for compilation and also a classpath that is inserted into the .jar file's manifest.
Here's the Ant file:
<?xml version="1.0" encoding="UTF-8"?>
<project name="InaneInteraction" default="rebuild" basedir=".">
<loadproperties srcfile="build.prop" />
<target name="rebuild" description="Clean compiled binaries then build the program" depends="clean,compile,release" />
<target name="-make-libs-paths">
<mkdir dir="${output_folder}"/>
<mkdir dir="${library_folder}"/>
<copy todir="${library_folder}">
<fileset dir="../jme/target">
<include name="**/*.jar"/>
<exclude name="**/jmetest.jar"/>
<exclude name="**/jmetest-*.jar"/>
</fileset>
<fileset dir="../jme/lib">
<include name="*.jar"/>
</fileset>
<fileset file="../jmephysics/ant/lib/junit.jar"/>
<fileset file="../jmephysics/release/jme-physics.jar"/>
<fileset file="../jmephysics/impl/joode/lib/joode.jar"/>
<fileset file="../jmephysics/impl/ode/lib/odejava-jni.jar"/>
</copy>
<path id="classpath">
<pathelement path="${project.jdk.classpath}" />
<fileset dir="${library_folder}" id="libslist">
<include name="*.jar"/>
</fileset>
</path>
<pathconvert property="buildclasspath" dirsep="/" refid="libslist">
<mapper type="regexp" from=".*(lib.*)" to="out/1" />
</pathconvert>
<pathconvert property="jarclasspath" pathsep=" " dirsep="/" refid="libslist">
<mapper type="regexp" from=".*(lib.*)" to="out/1" />
</pathconvert>
</target>
<target name="compile" description="Compile the source" depends="-make-libs-paths">
<mkdir dir="${binary_folder}"/>
<javac
srcdir="${source_folder}"
destdir="${binary_folder}"
classpath="${buildclasspath}"
debug="on">
</javac>
</target>
<target name="release" description="Create a jar from binaries and import needed libraries and files" depends="-make-libs-paths">
<jar destfile="${jar_location}" basedir="${binary_folder}">
<fileset dir="${binary_folder}">
<include name="**/*.class"/>
</fileset>
<manifest>
<attribute name="Built-By" value="${built_by}"/>
<attribute name="Main-Class" value="${main_class}"/>
<attribute name="Class-Path" value="${jarclasspath}"/>
</manifest>
</jar>
</target>
<target name="run" description="Run the program from the jar">
<java fork="true" dir="${output_folder}" jar="${jar_location}"></java>
</target>
<target name="clean" description="Cleanup compiled binaries, libraries, media, and archives">
<delete dir="${binary_folder}"/>
<delete dir="${output_folder}"/>
</target>
</project>
And build.prop:
source_folder=src
manifest_location=Manifest
resource_folder=res
binary_folder=bin
output_folder=out
jar_location_output=InaneInteraction.jar
jar_location=${output_folder}/${jar_location_output}
library_folder=${output_folder}/lib
main_class=com.nadir_seen_fire.games.inaneinteraction.ClientStart
built_by=Daniel Friesen
project_name=Inane Interaction
The build output:
Buildfile: C:cygwinhomeDanielideworkspaceInaneInteractionbuild.xml
clean:
[delete] Deleting directory C:cygwinhomeDanielideworkspaceInaneInteractionout
-make-libs-paths:
[mkdir] Created dir: C:cygwinhomeDanielideworkspaceInaneInteractionout
[mkdir] Created dir: C:cygwinhomeDanielideworkspaceInaneInteractionoutlib
[copy] Copying 22 files to C:cygwinhomeDanielideworkspaceInaneInteractionoutlib
compile:
[mkdir] Created dir: C:cygwinhomeDanielideworkspaceInaneInteractionbin
[javac] Compiling 3 source files to C:cygwinhomeDanielideworkspaceInaneInteractionbin
release:
[jar] Building jar: C:cygwinhomeDanielideworkspaceInaneInteractionoutInaneInteraction.jar
rebuild:
run:
[java] java.lang.NoClassDefFoundError: com/jmex/game/state/GameState
[java] Exception in thread "main"
[java] Java Result: 1
BUILD SUCCESSFUL
Total time: 10 seconds
And just for more information:
The lib directory after building contains:
- jinput.jar
- jme.jar
- jme-audio.jar
- jme-awt.jar
- jme-collada.jar
- jme-editors.jar
- jme-effects.jar
- jme-font.jar
- jme-gamestates.jar
- jme-model.jar
- jme-physics.jar
- jme-scene.jar
- jme-terrain.jar
- jme-xml.jar
- jogg-0.0.7.jar
- joode.jar
- jorbis-0.0.15.jar
- junit.jar
- junit-4.1.jar
- lwjgl_util_applet.jar
- lwjgl.jar
- odejava-jni.jar
And this is the MANIFEST.MF that ends up inside of the .jar:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 1.6.0_02-b06 (Sun Microsystems Inc.)
Built-By: Daniel Friesen
Main-Class: com.nadir_seen_fire.games.inaneinteraction.ClientStart
Class-Path: out/lib/jinput.jar out/lib/jme-audio.jar out/lib/jme-awt.j
ar out/lib/jme-collada.jar out/lib/jme-editors.jar out/lib/jme-effect
s.jar out/lib/jme-font.jar out/lib/jme-gamestates.jar out/lib/jme-mod
el.jar out/lib/jme-physics.jar out/lib/jme-scene.jar out/lib/jme-terr
ain.jar out/lib/jme-xml.jar out/lib/jme.jar out/lib/jogg-0.0.7.jar ou
t/lib/joode.jar out/lib/jorbis-0.0.15.jar out/lib/junit-4.1.jar out/l
ib/junit.jar out/lib/lwjgl.jar out/lib/lwjgl_util_applet.jar out/lib/
odejava-jni.jar
And trying to run it from command line gives me this:
C:cygwinhomeDanielideworkspaceInaneInteractionout>java -jar InaneInteract
ion.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version n
umber in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
4)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
I guess I'm probably missing something, but I don't know what kind of other things I need to have ant include, and where/how to include them.