1

I have a .java file that I created in eclipse. I managed to make a .jar out of it, but I don't know how to put my images folder into the jar, nor do I know how to make the jar run?

Should it run already, or would it just be an archive like a .zip?

Thank you guys so much for your help here, because I am completely and totally lost when it comes to this. I have been programming in java (just making .java files in JCreator basically) for about 2 years now.

I have searched and searched but never found a good answer. Anyone that can shed the like on how running .java files as an application and things work, that would be awesome.

P.S. I am using GUI, and the code is correct.

Thank you so much!

  • 3
    Typically, images are put into a resource folder that's included in the project. To create an executable jar file, do `File > Export > Java > Runnable JAR file`. – mre Dec 28 '11 at 18:53
  • 1
    See also this [answer](http://stackoverflow.com/a/8462092/230513). – trashgod Dec 28 '11 at 18:57
  • it doesn't let me do an executable jar file though. – Kyle Lawson Dec 28 '11 at 19:07
  • 1
    There are several tools & Eclipse plugins that let you create a runnable jar from a project. Those let you also aggregate several parts of your application. The trick is though to create a good scheme for loading images. If they are just building parts of the GUI, you should put them in the source folders (or a .res package in the source folders) - Eclipse will copy them into the class folder, so they become resources automatically. – Maarten Bodewes Dec 28 '11 at 19:25

1 Answers1

0
  • What is a runnable jar?

A jar is a archive (it uses the same file format of a ZIP) that contains program artifacts: compiled classes, images, configuration files and other resources.

To be a runnable jar it must contain a special file, called manifest (the manifest support electronic signing, version control, package sealing) with a Main-Class: project.name.EntryPoint entry that specifies the class that is the start point of the program.

This can be easily achieved by using the Eclipse feature File > Export > Java > Runnable JAR file.

  • How to run a runnable jar?

Using the command line, just do java -jar <jar_file_path>. But nowadays the graphic shells of the operating systems (Windows Explorer / Gnome / KDE) already call java when you double-click a jar file.

  • How to put images on the .jar?

You can do this specifying on the Eclipse project that the images folder is also a source folder. Now when exporting the project to the jar file it will include them.

MrJames
  • 676
  • 2
  • 8
  • 20