LWJGL Forum

Programming => General Java Game Development => Topic started by: strollingchimp on September 29, 2011, 21:00:33

Title: Problem with packaging
Post by: strollingchimp on September 29, 2011, 21:00:33
First of all, sorry if this is in the wrong place, I'm a noob.

I am using slick-util and lwjgl to write this game.

I am having a problem with making a runnable jar from Eclipse. The jar seems to package fine and it appears on my desktop. I told Eclipse to package the required libraries into the output jar. However when I go to run the jar it does not run. No error it just doesn't run. So, I decide to run it through cmd but it still does not work. This is the output that I get:

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:58)
Caused by: java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.loadLibrary0(Unknown Source)
        at java.lang.System.loadLibrary(Unknown Source)
        at org.lwjgl.Sys$1.run(Sys.java:73)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
        at org.lwjgl.Sys.loadLibrary(Sys.java:82)
        at org.lwjgl.Sys.<clinit>(Sys.java:99)
        at org.lwjgl.opengl.Display.<clinit>(Display.java:130)
        at platformertrylwjgl.PlatformerTry.startGame(PlatformerTry.java:37)
        at platformertrylwjgl.PlatformerTry.main(PlatformerTry.java:170)
        ... 5 more

Can somebody please help, I am a noob and I do not know what to do.
Title: Re: Problem with packaging
Post by: kappa on September 29, 2011, 21:13:30
hmm, I'd go with something a little more simple, like the JarSplice tool found here (http://ninjacave.com/jarsplice).

See this link (http://lwjgl.org/forum/index.php/topic,4186.msg22615.html#msg22615) for some quick instructions on how to use it.
Title: Re: Problem with packaging
Post by: strollingchimp on September 30, 2011, 20:09:39
I am having a few problems with that too. Whenever I try to run the jar that jarsplicer compiles I get an error "Invalid or corrupt jar file". Did I add the main class right?
Title: Re: Problem with packaging
Post by: kappa on September 30, 2011, 20:25:17
that error usually means that the fat jar failed on creation. Likely you're doing one of the steps wrong, try running jarsplice from the cmd/console "java -jar jarsplice-*.jar" it should give you an exception on why its failing to create the jar.
Title: Re: Problem with packaging
Post by: jediTofu on October 01, 2011, 04:45:27
Java Web Start is good too.  Check out the wiki for that.  You could also do a bash shell script file for linux/macosx and a batch file for windows.
The shell script would be like this (assuming the lwjgl directory is in the current directory):

RunMe.sh
Code: [Select]
#!/bin/sh
java -Djava.library.path=./lwjgl/native/linux -cp .:lwjgl/jars/lwjgl.jar:lwjgl/jars/lwjgl_util.jar:lwjgl/jars/jinput.jar:myjar.jar  MyGame

Batch would be the same, except ";" instead of ":", "native/windows", no "#!/bin/sh", and renamed to RunMe.bat.
Title: Re: Problem with packaging
Post by: strollingchimp on October 01, 2011, 08:06:02
I tried running jarsplice from cmd and the message I got was this

java.util.zip.ZipException: duplicate entry: liblwjgl.so
        at java.util.zip.ZipOutputStream.putNextEntry(Unknown Source)
        at java.util.jar.JarOutputStream.putNextEntry(Unknown Source)
        at org.ninjacave.jarsplice.core.Splicer.addNativesToJar(Splicer.java:141
)
        at org.ninjacave.jarsplice.core.Splicer.createMacApp(Splicer.java:64)
        at org.ninjacave.jarsplice.gui.CreatePanel.actionPerformed(CreatePanel.j
ava:117)
        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.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$000(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour
ce)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour
ce)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour
ce)
        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)
File Saved as C:\Users\Matt\Desktop\game.jar

Does that mean anything to you?
Title: Re: Problem with packaging
Post by: kappa on October 01, 2011, 10:02:45
I tried running jarsplice from cmd and the message I got was this

java.util.zip.ZipException: duplicate entry: liblwjgl.so
        at java.util.zip.ZipOutputStream.putNextEntry(Unknown Source)
        at java.util.jar.JarOutputStream.putNextEntry(Unknown Source)
        at org.ninjacave.jarsplice.core.Splicer.addNativesToJar(Splicer.java:141
)
...

Does that mean anything to you?
Yes it basically means that you are trying to add the file liblwjgl.so twice to the zip, which is why its failing. Check the natives tab to ensure that file is only added there once, secondly check that jars tab and make sure that the file isn't in any of the jars you add there (especially as slick has that in linux-natives.jar, so just be sure you are not adding the native jars to that tab).
Title: Re: Problem with packaging
Post by: strollingchimp on October 01, 2011, 16:24:48
So that has solved one problem, but whenever I run from CMD I get "Could not find or load main class PlatformerTry."

I don't really know where to find the name of the main class. I just used the project name.

Just to clear things up, I am not the person who coded this game. A friend did, I am a Java noob.
Title: Re: Problem with packaging
Post by: kappa on October 01, 2011, 16:50:18
yeh, entering the name of the project is wrong and won't work.

You have to find out which is the main class in the project and enter that exactly (its case sensitive) and you also have to prepend it with any package names that it may be in.

You'll need the above information whatever method you use, otherwise the JVM will not know which class to run from.
Title: Re: Problem with packaging
Post by: strollingchimp on October 01, 2011, 18:54:16
I'm guessing it is the name of the thing in the src folder in eclipse. Which in my case is platformertrylwjgl. I think the package names are platformertrylwjgl.graphics etc. Am I right?
Title: Re: Problem with packaging
Post by: kappa on October 01, 2011, 18:59:43
if 'platformertrylwjgl' is the name of the main class (i.e. the class that you click in eclipse to run the game) and the package name is 'platformertrylwjgl.graphics' (will be the first line of code in the main class file). Then the name of the main class that you need to enter is 'platformertrylwjgl.graphics.platformertrylwjgl' (without quotes).
Title: Re: Problem with packaging
Post by: strollingchimp on October 01, 2011, 19:06:06
Okay, now I think I understand. Just one last question, in the main file that I run from there is code that says public class PlatformerTry, would that be the main class?
Title: Re: Problem with packaging
Post by: kappa on October 01, 2011, 19:09:16
Yes.

Do keep in mind that class names are case sensitive so 'platformertrylwjgl.graphics.PlatformerTry'.
Title: Re: Problem with packaging
Post by: strollingchimp on October 01, 2011, 19:10:47
Also, as I have multiple packages do I need to enter platformertrylwjgl.graphics.platformertrylwjgl.entity or do I need to enter platformertrylwjgl.graphics.entity?
Title: Re: Problem with packaging
Post by: kappa on October 01, 2011, 19:16:18
doesn't matter about multiple packages, in this case you only need the package which the main class is inside.
also consider joining the LWJGL IRC Channel (http://webchat.freenode.net/?channels=lwjgl), should be a better medium if you have lots of quick and small questions.
Title: Re: Problem with packaging
Post by: strollingchimp on October 01, 2011, 19:37:21
Thanks for the help and the link. It does run now but the application only opens for a second and then it closes again. This is the output:

Trying window - 1280x800
Window successful
Exception in thread "main" java.lang.ExceptionInInitializerError
        at platformertrylwjgl.PlatformerTry.loadGame(PlatformerTry.java:55)
        at platformertrylwjgl.PlatformerTry.startGame(PlatformerTry.java:46)
        at platformertrylwjgl.PlatformerTry.main(PlatformerTry.java:170)
Caused by: java.lang.RuntimeException: Resource not found: res/tex/TestTexture.p
ng
        at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoa
der.java:69)
        at platformertrylwjgl.graphics.TextureManager.loadTexture(TextureManager
.java:26)
        at platformertrylwjgl.graphics.TextureManager.<clinit>(TextureManager.ja
va:20)
        ... 3 more
Title: Re: Problem with packaging
Post by: kappa on October 01, 2011, 20:17:04
looks like you left your game resources out when exporting the game jar from eclipse, namely:

Caused by: java.lang.RuntimeException: Resource not found: res/tex/TestTexture.png