This site requires JavaScript, please enable it in your browser!
Greenfoot back
LegendXV
LegendXV wrote ...

2014/2/2

Creating Jar with In-text Directories

LegendXV LegendXV

2014/2/2

#
So I used GreenfootImage quite often throughout my project (with a directory specific to my computer). Upon exporting the Jar, however, there would be errors since the directories would be incorrect (if I brought the Jar to another computer).
bourne bourne

2014/2/3

#
Edit: If you don't have the images in your project folder (typically the images folder), the images won't be packaged with the Jar. If you are on a different computer, using an absolute path would need to point to an image found on that computer
GreenfootImage(java.lang.String filename)
LegendXV LegendXV

2014/2/3

#
How do you use an absolute path?
bourne bourne

2014/2/3

#
By inputting that String into GreenfootImage constructor. An absolute path would be something like:
String absPath = "/Users/taylor/Documents/Programming things/Greenfoot/Testing/images/myImage.png";
LegendXV LegendXV

2014/2/3

#
But wouldn't that retrieve an incorrect directory since the directory changes on every computer?
bourne bourne

2014/2/3

#
Right, if you use absolute paths, you would encounter that dilemma. (I'm assuming that's what you have done?)
LegendXV wrote...
directory specific to my computer
LegendXV LegendXV

2014/2/3

#
Another question. I exported the file as a JAR ... but all the edits I made (text wise) have all vanished. All that remains are un-editable classes.
bourne bourne

2014/2/3

#
Did you use the built-in export to JAR function by the Greenfoot IDE? (Scenario->Share->Application) And what edits? Edits to the code? When you export to a JAR, you are suppose to keep the original project which has your code etc.
LegendXV LegendXV

2014/2/3

#
I exported to the same directory as my project folder. For some reason a duplicate folder was made with all my project images, etc, but the .txt files vanished. (Yes I did use the built-in export). And my .java files.
LegendXV LegendXV

2014/2/3

#
All that remains are ineditable .class files.
bourne bourne

2014/2/3

#
I just did a small test and the JAR file did not open when I exported it to inside the project folder (might have difficulties when it is pulling from that folder to create the JAR, at the same time creating the JAR there). But the files seemed to be still there
bourne bourne

2014/2/3

#
Are you by chance looking inside the JAR? Which would contain the .class files of your source and not the .java files. Otherwise if your .java files really are gone, you might need to use a decompiler.
LegendXV LegendXV

2014/2/3

#
Yeah Im not looking inside the jar for sure. Idk where all my editable files went to though :/
LegendXV LegendXV

2014/2/3

#
Okay, I'll lay it out in specific details. 1) I exported as a Jar. 2) I searched for my Jar and ran it. 3) There were directory errors so I copied and pasted my images into the right area to solve the issue. 4) The game ran perfectly. 5) I couldn't edit the game ... even opening it up in the Greenfoot Project. 6) My player.java reverted to an older version (practically brand new ... all there is are movement methods) 7) ALL of my .java files went completely missing (the current ones).
LegendXV LegendXV

2014/2/3

#
I lied. I was looking in ad uplicate project folder that I used earlier LOL.
You need to login to post a reply.