1

I have created a program in Java using eclipse that contains a couple of folders with graphics and files that get read from and written to. What I need is a way to export the whole program in some executable format so that anyone can run my program.

I've had a look around online and I notice that people suggest creating an executable JAR file. However I have my reservations about this since I suspect it will choose to ignore the graphics & other files that the program uses, only focusing on the actual source code.

Please could someone suggest a solution to this issue, it is absolutely essential that the files and graphics are packaged up with the rest of the code.

On another related note; at present I'm referencing the files & graphics using files paths that are specific to my computer. If I were to use another solution such as creating an installable program how should I handle these filepaths? Apologies if this is a naive question, however I'm new to this sort of thing.

1 Answer 1

3

However I have my reservations about this since I suspect it will choose to ignore the graphics & other files that the program uses, only focusing on the actual source code.

When you think you may have a solution but it doesn't work, you should test that theory.

A jar file is absolutely the right solution for this. However, you need to make sure that Eclipse considers them as resources on the build path so that it will copy them into the jar file. Then you just need to refer to them from the jar file:

On another related note; at present I'm referencing the files & graphics using files paths that are specific to my computer. If I were to use another solution such as creating an installable program how should I handle these filepaths?

Use Class.getResource() or Class.getResourceAsStream() or the ClassLoader equivalents. That will let you load your resources directly from the jar file, without even having separate files on the file system.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your help on this. Please could you clarify whether the ability to write the files in the jar will still be possible?
@TheCrazyChimp: No - at least not without a pretty large amount of work. The idea is that these are resources to be loaded, not that it's just a file system you can use like any other file system.
Thank you - I was not aware of this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.