0

question is: what is included in the executable jar when exporting as such from Eclipse? I am asking because I would like to know, for example, if I have an image in the project root, would that image be included in the export?

Clarification: I am talking about runnable jar files (edited)

CosminO
  • 5,018
  • 6
  • 28
  • 50
  • 3
    Why don't you just give it a try and check what is or is not in the resulting jar file? – Steven Devijver Jun 19 '12 at 09:43
  • @StevenDevijver at the moment, I cannot export the project and get to that part and see if it works. I will look for some app that can open a .jar file. Ty for your comment. – CosminO Jun 19 '12 at 09:45
  • @Ameoo App, that can open jar file: 7Zip, WinRAR – brimborium Jun 19 '12 at 09:47
  • 1
    Btw, every jar file is executable with `java -jar`. And I haven't seen that terminology in Eclipse yet. I guess you are talking about "Runnable JAR files" (which define their Main-Class in the manifest)? – brimborium Jun 19 '12 at 09:49

2 Answers2

1

You mean File->Export...->Runnable JAR file? Only the class files are in the jar and - if this option is selected - the linked libraries. You can, however create a source folder (name it "ressources" or so) and this will also be included in your jar.

brimborium
  • 9,362
  • 9
  • 48
  • 76
  • I have created a new source folder and it does not get exported in the jar – CosminO Jun 19 '12 at 10:23
  • 1
    @Ameoo I just tested that and it worked fine. I have created a source folder (`right click on project->New->Source Folder`) and named it "test". After that I moved a File "asdf" in there and exported the project into jar (`right click on project->Export...->Java->Runnable JAR file`). Note that the file "asdf" will be in the root of the jar file, there will **not** be any folder "test". – brimborium Jun 19 '12 at 10:30
  • yes, same result here. In code I am using one file as "test/filename.abc" and it works. After the export, I get the same message as I would get when the filename.abc wasn't found, because it is exported in the root folder. How can I overcome this problem? – CosminO Jun 19 '12 at 10:33
  • @Ameoo by loading the file as a ressource: [link to SO question](http://stackoverflow.com/a/2393302/1137043). Of course, you can also load something other than an image. Look at [this SO question](http://stackoverflow.com/q/3831845/1137043). – brimborium Jun 19 '12 at 10:35
  • but where would I add that code, since I want to run exactly what I have in eclipse, I don't want to use this jar in any other place, this IS the whole application. That's why I'm exporting it as Runnable Jar. Is there absolutely no way of making eclipse export the source folder as a folder in the jar? – CosminO Jun 19 '12 at 10:51
  • @Ameoo Sure there is, you can just create a folder in your newly created source folder and put your file in there. It will then be put into a subfolder in the jar. – brimborium Jun 19 '12 at 11:47
1

Eclipse JAR exporter follows JAR Package Specification: http://docs.oracle.com/javase/1.4.2/docs/guide/jar/jar.html

But as always - the best option to learn is just give it a try. It's quick and straightforward.

Maciej
  • 140
  • 3