1

I have an Java desktop program which uses a "file" folder to keep logs and "image" folder to get images of its gui. I want to publish this program with ".class" files visible ( so that i can update them ).

1-) In eclipse, when i use export--> Jar or export-->Executable Jar options. Its wraps everything in one jar and my program doesn't work ( probably because it cannot find image files ). I think i remember a way to publish the code as it is using eclipse but cannot find it :/. How can i publish my code keeping the folders i want with the program?

2-)Is it a bad idea to keep visable ".class" files for updates? ( i don't, also want people sneak in the code because it will have database url's and such ). What are my alternatives? How do you make your updates?

Thanks for the answers and pardon me if i asked something has already be asked and answered gazilion times :/(.

Ozan
  • 206
  • 1
  • 4
  • 13
  • 2
    It's much easier to update a single jar file containing everything than updating individual .class files. You should package everything in a jar file, and show us your project layout, the contents of the generated jar, and the relevant code so that we can explain you why loading the images doesn't work. – JB Nizet Jan 24 '14 at 07:10
  • As a jar file is simply a zip file, the security concerns you have with `visible .class` files apply equally. – Scary Wombat Jan 24 '14 at 07:13

2 Answers2

0

WOW, your comment sparked lights in my head =). Problem solved :).

What i did is, export runnable jar, and selected libraries to be copied in folder. And then, i copied the external, namely "files" and "images" folders to the folder where my jar file is. And it worked! =).

//For the second question, yep this way the ".jar" file is minimal so it can be updated easily.

For the second question, i showed images as resources ( can be done with right clicking relative folder in eclipse ) as recommended.

Thanks for your comment.

Ozan
  • 206
  • 1
  • 4
  • 13
  • 2
    You'd better also store the images and files inside the jar. – JB Nizet Jan 24 '14 at 07:22
  • But it would increase the size of jar? In case of updating, wouldn't it be a problem? And also, how can i address them from my code? – Ozan Jan 24 '14 at 07:37
  • 1
    So what? Do you have thousands of high-quality images, so much that replacing the whole jar instead of individual images would cause a problem? My guess is that you have a few icons, that would increase the jar size of a few KBs. And, just as .class files, updating a single jar file is easier than updating several individual images. To load images from a jar file (from the classpath in general in fact), see http://stackoverflow.com/questions/16486858/packaging-a-program-containing-images and http://stackoverflow.com/questions/17085692/load-image-from-jar-and-outside-it-in-eclipse – JB Nizet Jan 24 '14 at 07:44
0

A lot of these questions will vanish once you start using maven as your build environment. Packaging and resources handling is important if you want to deploy your java code to the outside world (sticking to standard patterns).

A common pattern to load resources inside your Jar (as I understood, from your java code) is to use

MyClass.class.getRessourceAsStream("yourfile.whatever")

Or use FileIO.

There are a lot of tutorials and resources outside regarding maven and it will help you not beeing to much concerned copying anything by hand in your build process. Everything else than coding should be automated by your environment.

chris polzer
  • 3,219
  • 3
  • 28
  • 44