Impmaster
|
|
« 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
|
|
|
|
Sean A.
|
|
« 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
|
|
« 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
|
|
|
|
Sean A.
|
|
« 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
|
|
« 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
|
|
« 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
|
|
|
|
Impmaster
|
|
« 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
|
|
|
|
rosholger
Level 1
|
|
« 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
|
|
« 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
|
|
|
|
R.D.
|
|
« 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
|
|
|
Logged
|
|
|
|
Impmaster
|
|
« 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.
|
|
|
Logged
|
|
|
|
rosholger
Level 1
|
|
« Reply #11 on: April 27, 2013, 08:31:52 AM » |
|
how are you referencing them now?
|
|
|
Logged
|
|
|
|
Impmaster
|
|
« 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
|
|
|
|
Sean A.
|
|
« 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
|
|
« Reply #14 on: April 28, 2013, 01:26:14 AM » |
|
|
|
|
Logged
|
|
|
|
nikki
|
|
« Reply #15 on: April 28, 2013, 02:18:21 AM » |
|
just take it easy.
build a little test app. Add the references and make it work as clean as possible. take note of all the tiny steps.
learn it and apply the knowledge to your bigger project. don't panic in your bigger project, best case you probably accidentally fix it. Which is bad because you haven't learned a thing then.
have fun!
|
|
|
Logged
|
|
|
|
rosholger
Level 1
|
|
« Reply #16 on: April 28, 2013, 04:52:14 AM » |
|
shouldn't you reference them as data/image instead of src/data/image, since you don't want to reference the copies in the src folder but in the output folder/the jar
|
|
|
Logged
|
|
|
|
Impmaster
|
|
« Reply #17 on: April 28, 2013, 05:14:35 PM » |
|
I did that, but now it's having some glitch where some of my classes work, but others, with images IN THE SAME FOLDER do not work...
|
|
|
Logged
|
|
|
|
rosholger
Level 1
|
|
« Reply #18 on: April 29, 2013, 05:22:35 AM » |
|
are there any way in eclipse to specify what files get "compiled"(moved to output), like say files ending with .png. i know i had problem with that(in idea)
|
|
|
Logged
|
|
|
|
R.D.
|
|
« Reply #19 on: April 30, 2013, 02:47:50 AM » |
|
It seems like you have inconsistent code here an there. Your resources should follow a given naming convention. So let's say you have some images in src/data/images and you load them via the Image C'Tor. This should look like this: Image image = new Image("data/images/filename.png");
This should also work if you move the data folder outside the src folder directly into the project tree. So now you go on File/Export and choose Java/Export as Runnable jar. The dialog which pops up should already do everything for you. Make sure you select the correct main class. The library handling can be set like you want (I have to to generate sub folder for external jars or classes). The dialog you used is probably the normal JAR Export. This is mostly used for libraries. And as said, make sure you have the same naming convention over your resources. I normally do this: public class Resources { public static class TEXTURES { public static final String PLAYER_ANIMATIONS = "data/images/player-animations.png" } public static class SOUNDS { public static final String HIT1 = "data/sounds/hit1.ogg" } ... }
It's pretty straight forward and allows me to use a loader to go through all textures and sounds automatically.
|
|
|
Logged
|
|
|
|
|