0

I'm currently learning Java and I'm doing a project of html "creation".

The point its than I want to store an image in the jar file and be able to access it in run-time (I'm going to copy the image to a certain folder), but i don't know where to put the image, how to access it from my code, or how to compile it properly. I'm currently using ant for the compilation process.

I should give my professor the whole source code and resources, then, he should be able to run ant proyectX and it should create the .jar file as an stand-alone app.

I don't want to use a external URL because he is going to test it and maybe, after seeing the code, he would disconnect himself from the internet. I can't use any external library, just pure java code.

Thank you, and sorry for the bad english.

Ulilop
  • 51
  • 1
  • 6

1 Answers1

0

You should create a folder in your jar (for example "img") where you will keep all images.

After that you can get the image this way:

InputStream input = getServletContext().getResourceAsStream("/img/image_1.jpg");

Or this way:

File file = getRequest().getServletContext().getRealPath("/img/image_1.jpg");

Loading a file image in a war project

File path to resource in our war/WEB-INF folder?

i.merkurev
  • 465
  • 2
  • 8