0

I am fairly new to java. I have written an application that basically has a 50x50 grid of buttons, with each button opening a specific image related to that button. The images are stored on my file system.

The app works perfectly in Netbeans, each button opens up the correct image.

I would now like to export the app to be able to share it with some people that are interested - however I am not sure what is the best way to do this. I have been googling this for days but haven’t found anything that really answers my question.

What I would prefer is this: The user installs/unzips/whatever the app, and as a result is left with a folder with all the image files (quite a lot of them and around 1Gb in size) and a runnable file, preferrably an .exe to run the program.

What would be the best way to achieve something like this?

At first I was thinking about including all the image files in a runnable JAR. The problem with this approach is that I would have to rewrite my code, as right now my code uses java.io.File to fetch the images and to my knowledge this doesn’t work inside a JAR. Also I would much prefer an .exe instead of a JAR.

Any help will be greatly appreciated!

gitblast
  • 1
  • 1

1 Answers1

0

as right now my code uses java.io.File to fetch the images

Are you saying that you use java.io.File to get a listing of available images or that you're using it to read an image?

If you need a list of images or resources inside a jar take a look at "How to list the files inside a JAR file?"

To read an image from inside a jar using JavaFX, you just need to get the URL to the image:

import javafx.scene.image.Image;

URL url = getClass().getResource("/path/inside/jar/myimage.png");
Image image = new Image(url.toExternalForm(), true);

As to the best way to deploy that app ... I would say that a 1GB app is a beast. Could you host the images on a web server and have the app lazily fetch the images as they need to be displayed?

hohonuuli
  • 1,974
  • 15
  • 15
  • Thanks for the answer. I was using java.io.File to read the images but updated it to using getResource and at least it works now. I agree 1Gb is a lot, but the app was made to make an existing web app faster. Having the images on the file system makes the images load instantly instead of a small delay, which is very important in my case. – gitblast May 15 '19 at 09:36