[java] Compiling Jar in Eclipse with LWJGL

Started by
14 comments, last by Stani R 16 years ago
Hi, Sorry to ask probs a very basic question. But i'm trying to compile my project that uses the LWJGL jar files. The main interface is in AWT. One of the JButtons on the interface opens up a new render window from the LWJGL library. The project works fine in eclipse and all the libraries are set up. However when i compile to a jar with all the LWJGL jars included, the 'Render' button doesnt do anything, i.e doesnt open a LWJGL window. The class path i have is: <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="src" path="src"/> <classpathentry exported="true" kind="lib" path="lwjgl.jar"/> <classpathentry exported="true" kind="lib" path="lwjgl_util.jar"/> <classpathentry exported="true" kind="lib" path="vecmath.jar"/> <classpathentry kind="output" path="bin"/> </classpath> Ive been playing around with this for hours and cant get the render button to respond. Any ideas? Thanks! Dan
Advertisement
Assuming it's possible to open a LWJGL window from AWT (I never tried, but I think it is): run it from a console, there should be some error being reported. Probably you did not include the LWJGL dll's in the correct place (just the jars is not enough) - I think having them in the same directory should work, otherwise use -Djava.library.path=path/to/dlls

What I usually do is write an ant script that builds the jar and copies all jars, library files, and data files to a separate directory. Eclipse makes this really easy, just add a script to your project, right click and select run.
Hi, thanks for the reply.

Ive put the dll's and the jar files in the same directory but still no luck.

Where do i use 'Djava.library.path=path/to/dlls'?

Thanks
Dan
As argument to the VM.

java -Djava.library.path=path/to/dll -jar yourgame.jar

Run it from a console window. But you shouldn't need to add the path if it's in the same directory. There's no error being reported on the console when you press the button?
Hey,

Just ran it from the console. It says 'Unable to access Jar File' when i use that line. It's strange because when you execute the jar file normally by double clicking it it runs ok (except without the working button), but not from the command line? :s

Thanks
Dan
It can't find yourgame.jar since it doesn't exist, or you're in the wrong directory... Don't use it verbatim. You need to substitute your jar's name for "yourgame.jar", and something else for "path/to/dll". You also have to navigate to the directory with the jars first.
hi lightbringer,

Thanks for the help so far.

Yeh ive been using my own setup, the printout from the console is:

C:\Documents and Settings\Daniel Barrett>java -Djava.library.path="org.eclipse.j
dt.launching.JRE_CONTAINER" diss10.jar
Exception in thread "main" java.lang.NoClassDefFoundError: diss10/jar


I've also tried:

C:\Documents and Settings\Daniel Barrett>java -Djava.library.path="C:\Program Fi
les\Java\jre1.6.0_02" diss10.jar
Exception in thread "main" java.lang.NoClassDefFoundError: diss10/jar


Unfortunately they teach you everything on my uni course except how to compile jars :s.

Thanks
Dan
library path should be the path to lwjgl's dlls, not one of those you put. If it's in the same directory, leave it out, or use a dot. You also did not specify that you are loading a jar and not a class.

Try this:
java -Djava.library.path=. -jar diss10.jar

or alternatively:
java -jar diss10.jar

Then post back your results. This is assuming, of course, that you already compiled a jar called diss10.jar. If you didn't, then use an ant script
Hey,

for:

java -Djava.library.path=. -jar diss10.jar

It says:

Exception in thread "main" java.lang.NoClassDefFoundError: diss10/jar


for:
java -jar diss10.jar

It says:

Unable to access jarfile diss10.jar

Sorry i didnt mention the jar part :(

Thanks
Dan
Are you running that from the directory containing your jar?

Quote:Original post by daemon2008
Sorry i didnt mention the jar part :(

No no I just mean that you need to use -jar switch for jars :)

This topic is closed to new replies.

Advertisement