Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

997685 Posts in 39115 Topics- by 30521 Members - Latest Member: Gisnu

April 16, 2014, 06:28:50 AM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)How to export a slick2d project in Eclipse as a .jar
Pages: [1] 2
Print
Author Topic: How to export a slick2d project in Eclipse as a .jar  (Read 1287 times)
Impmaster
Level 10
*****


Scary, isn't it?


View Profile Email
« on: April 25, 2013, 05:43:33 PM »

Hey all. I've finished my first game, and I can't seem to manage to export it. It runs perfectly in Eclipse (well.... "perfectly"), but if I use the export as runnable jar function, the jar doesn't work. I'm using slick2d. Any help?
Logged

Do I need a signature?
Sean A.
Level 8
***



View Profile Email
« Reply #1 on: April 25, 2013, 09:01:26 PM »

I've never used slick2d but I've had a similar problem before with LWJGL, what you need is JarSplice (http://ninjacave.com/jarsplice) It is a really easy step by step way to make a runnable .jar (or .exe or .app or whatever) from your project. So first you export your game .jar using Eclipse, then open JarSplice and add that .jar as well as any other libraries and native libraries, select which platforms and it'll spit out a runnable file. I have no idea why it wasn't built into Eclipse in the first place.
Logged
Impmaster
Level 10
*****


Scary, isn't it?


View Profile Email
« Reply #2 on: April 26, 2013, 02:13:56 AM »

Alright. I tried doing that, and it seemed to create a .jar. At least now it stopped giving me errors that the jar did not have the right libraries. But now, it crashes on startup due to the fact that it cannot get my resources. My resources folder is in my src folder in Eclipse, and works fine there. However, when Eclipse exports as a .jar, it seems to not add in a src folder. So all my links are wrong. What should I link to now?
Logged

Do I need a signature?
Sean A.
Level 8
***



View Profile Email
« Reply #3 on: April 26, 2013, 05:39:03 AM »

How are you referencing the assets from within your project, is it by a path such as 'assets/image.png' because from what I've found using JarSplice is that if you reference something in your project like 'textfile.txt' then if you put that text file in the same folder as the .jar you made using JarSplice it points to the correct file so if you put your assets folder right beside your .jar and reference it using 'assets/image.png' it should work.

Hope that helps.
Logged
rosholger
Level 1
*



View Profile Email
« Reply #4 on: April 26, 2013, 05:45:05 AM »

as long as you are linking to them in a relative way (ie "assets/text.txt" instead of "C:\jada\jada\jada\text.txt") i think slick2d fixes the liks for you, at least for images and sound
Logged
Impmaster
Level 10
*****


Scary, isn't it?


View Profile Email
« Reply #5 on: April 26, 2013, 10:53:06 PM »

How are you referencing the assets from within your project, is it by a path such as 'assets/image.png' because from what I've found using JarSplice is that if you reference something in your project like 'textfile.txt' then if you put that text file in the same folder as the .jar you made using JarSplice it points to the correct file so if you put your assets folder right beside your .jar and reference it using 'assets/image.png' it should work.

Hope that helps.

This seems to work, but it's kind of stupid. Why can't my files go into the jar? It makes it impossible to export as a .exe or .app.
Logged

Do I need a signature?
Impmaster
Level 10
*****


Scary, isn't it?


View Profile Email
« Reply #6 on: April 26, 2013, 11:01:58 PM »



Why is my data folder, which is in the src folder, not being exported? The folders inside are, but I can't see the data.
Logged

Do I need a signature?
rosholger
Level 1
*



View Profile Email
« Reply #7 on: April 27, 2013, 02:17:53 AM »

Why not try putting them inside the default package in a like a resources package?
Logged
Impmaster
Level 10
*****


Scary, isn't it?


View Profile Email
« Reply #8 on: April 27, 2013, 03:02:49 AM »

They are, unless I'm misinterpreting you. All my resources are in the src folder, inside a "data" folder. I can't see that "data" folder in the above image.
Logged

Do I need a signature?
R.D.
Level 1
*


Hats = Awesome


View Profile
« Reply #9 on: April 27, 2013, 03:49:10 AM »

Normally eclipse should handle this for you. If the your resource folder is inside the src folder. in ends up in the jar file. If you have the resource folder outside you must copy it next to your jar. Slick2D automatically checks both paths.
I'm not sure about it, but is this the "Export Runnable Jar" dialog? If not try using this one Smiley
Logged

Impmaster
Level 10
*****


Scary, isn't it?


View Profile Email
« Reply #10 on: April 27, 2013, 07:38:20 AM »

I opened my .jar, and the data folder is in there. However, there does not seem to be a src folder anymore. Should I edit my references? If so, to what? If I do it as data/image, I have to place the data folder in the containing folder of the app.



I hate exporting in Java.  Waaagh!
Logged

Do I need a signature?
rosholger
Level 1
*



View Profile Email
« Reply #11 on: April 27, 2013, 08:31:52 AM »

how are you referencing them now?
Logged
Impmaster
Level 10
*****


Scary, isn't it?


View Profile Email
« Reply #12 on: April 27, 2013, 07:08:48 PM »

Currently I am referencing them as src/data/image, but there does not seem to be a src folder anywhere in the .jar, as it gets removed in the export. Maybe I could make it not get removed?....

What should I do, oh great and mighty Java gods who have most likely done at least 1 more game than me...
Logged

Do I need a signature?
Sean A.
Level 8
***



View Profile Email
« Reply #13 on: April 27, 2013, 08:24:48 PM »

So since java compiles to class files the src folder may not be inside the jar. I think there is a checkbox in eclipse to include the source files when exporting. You could try that but I also think that any assets should be in an assets folder in the project folder not the source folder.
Logged
Impmaster
Level 10
*****


Scary, isn't it?


View Profile Email
« Reply #14 on: April 28, 2013, 01:26:14 AM »

I moved the data folder outside of the src folder, and I made it all the references now just "image". This works for the first two states that I have, but breaks my third state. (sigh) I think it's a problem with references somewhere, cause my third state also uses images from the same folder, and I used the same references, but it doesn't work. NOTHING EVER WORKS IN MY CODE.  Waaagh! Crazy Epileptic
Logged

Do I need a signature?
Pages: [1] 2
Print
Jump to:  

Theme orange-lt created by panic