• Advertisement
Sign in to follow this  

[java] Compiling Jar in Eclipse with LWJGL

This topic is 3578 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites

Hey, i got the console part working!

I just pressed the render button and got:

importFromStream(): Load object from OBJ stream...
GL_OBJ_Reader: read 4032 faces in 1 groups
importFromStream(): models has 4032 faces and 2082 vertices.
Exception occurred during event dispatching:
java.lang.NoClassDefFoundError: org/lwjgl/opengl/Display
at render.GLRenderer.createWindow(GLRenderer.java:236)
at render.GLRenderer.init(GLRenderer.java:140)
at render.GLRenderer.run(GLRenderer.java:123)
at UserInterface.renderModel_actionPerformed(UserInterface.java:674)
at UserInterface.access$0(UserInterface.java:661)
at UserInterface$1.actionPerformed(UserInterface.java:233)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Thanks
Dan

Share this post


Link to post
Share on other sites
It means that lwjgl.jar isn't found on the classpath. Check by opening the jar with an archive program and reading the manifest file. Easiest way to fix that I know of would be using an ant script to compile the jar.

One note: the classpath you posted is for your project, but not for the jar you made. If you added the lwjgl.jar etc into your own jar directly, it won't work either because a jar cannot be read from inside another jar. You might unpack it and combine the trees, but it's easier to get an ant script to generate the correct manifest for you. Here's a sample script, I don't have time to edit it much since I have to leave right now:


<project name="solariad"
default="run"
basedir="f:/redmesa/code">
<description>
Ant targets for Solariad
</description>


<!-- set global properties for this build -->
<property name="dist" location="../dist/sol" />
<property name="obj-bin" location="sol2/bin" />


<target name="run"
description="placeholder"
depends="copy-res, make">
</target>

<target name="copy-res" description="copy project files">
<!-- copy project data & other files -->
<copy todir="${dist}">
<fileset dir="../data/solariad/dist/"/>
</copy>


</target>

<target name="make"
description="generate the jar and launcher" >

<jar jarfile="${dist}/solariad.jar" basedir="${obj-bin}">
<manifest>
<attribute name="Class-Path" value="locale lib/lwjgl.jar lib/lwjgl_util.jar lib/jinput.jar lib/ogginputstream.jar lib/jogg-0.0.7.jar lib/jorbis-0.0.15.jar"/>
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Main-Class" value="sol.MainApp"/>
</manifest>
</jar>

</target>

</project>



Make a file called build.xml from inside Eclipse, in your project. Then edit/write script, and run it.

Share this post


Link to post
Share on other sites
Hey,

The classpath file is as follows:

<?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 kind="lib" path="LWJGL"/>
<classpathentry kind="lib" path="lwjgl_util.jar"/>
<classpathentry kind="lib" path="lwjgl.jar"/>
<classpathentry kind="lib" path="vecmath.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

The manifest file just says:

Manifest-Version: 1.0
Main-Class: UserInterface



Is there anything else that needs to be added to the manifest, as the classpath seems to include the libraries correctly

Thanks
Dan

Share this post


Link to post
Share on other sites
Quote:

The manifest file just says:

Manifest-Version: 1.0
Main-Class: UserInterface



Is there anything else that needs to be added to the manifest, as the classpath seems to include the libraries correctly


Yes, the manifest should read something like (for example):


Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 10.0-b19 (Sun Microsystems Inc.)
Built-By: stani
Main-Class: sol.MainApp
Class-Path: locale lib/lwjgl.jar lib/lwjgl_util.jar lib/jinput.jar lib
/ogginputstream.jar lib/jogg-0.0.7.jar lib/jorbis-0.0.15.jar



How to make it? Modify the script I posted above, or write the manifest by hand. I'll be back in about 5 hours.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement