wood burning stoves 2.0*
The moose likes IDEs, Version Control and other tools and the fly likes Problem with Eclipse exporting an executable Jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Problem with Eclipse exporting an executable Jar" Watch "Problem with Eclipse exporting an executable Jar" New topic
Author

Problem with Eclipse exporting an executable Jar

Randy Miller
Ranch Hand

Joined: Feb 13, 2012
Posts: 44
Hi guys!

The topic says it all: I basically want to export my current project via eclipse to create a runnable jar. So far so good. The project works just fine, BUT: My project is a bigger GUI, where I also use external pictures which are located inside a seperate folder INSIDE the project. Somehow, no matter how I try to export the project, it just won´t use these pictures when I try to start the runnable Jar.
The only thing that works is either: Export a runnable jar without the pictures OR export a normal jar, which is NOT runnable...
Does somebody have the same problems and a solution to this mess?

Greetings,

Randy
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5778
    
    7

Exactly where are the pictures located with the project's directory? Have you checked the created JAR file to see if he pictures are located anywhere in that JAR file? If they are, where are they in the JAR?


JBoss In Action
Randy Miller
Ranch Hand

Joined: Feb 13, 2012
Posts: 44
Hi Peter!

Looking at the eclipse environment, the pictures are located in a folder inside the project. When I start the application in Eclipse, everything´s perfectly fine.
But then, I tried to use the "Export"-function to create an executable Jar...Now, I can directly open this far and it starts running but it just won´t display the 3 pictures.
And seemingly, my property-files(also located inside the project folder) aren´t in use,also...
I unzipped the executable Jar and there´s NO pictures folder, NO property files,NOTHING...
Funny thing is,Eclipse just won´t create an executable Jar with these folders.So far I haven´t found an option to choose where I might tell eclipse to please include these folders as well during the creating process.
But, if I just simply create a normal jar, all folders are included correctly.Now,how may I create an executable jar with this "normal" jar?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5778
    
    7

You answered my second and third question, but didn't answer the first one.
Randy Miller
Ranch Hand

Joined: Feb 13, 2012
Posts: 44
Hi Peter!

Sorry for taking so long to answer but I´ve been crazy busy lately...
I´m not pretty sure what EXACTLY you mean by where the pictures are located with the project folder, but I´ll try my best to answer ;)
Basically I have my project folder, inside the project folder is the folder src and inside THIS folder is a package containing ALL classes.
The pictures,my property files etc are all located inside the source folder(src), but NOT inside the package itself.

Does this lead to my executable jar problems?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5778
    
    7

You are obviously looking at Eclipse's Project Explorer view. Look instead at the underlying directory structure using your OS' file manager. If I understand correctly, you have:

projectname/src/some.jpg
projectname/src/some.properties

Is this correct? (There is some confusion in my mind because your posts mentions a pictures folder)

While you are in the file manager, also look in the bin directory. That's where .class files go by default. Check to see if the properties and .jpg files got copied there. It's the bin directory that is used to build the final JAR.

Also, does the executable JAR contain additional JAR files? If so, are your pictures and properties in any of them? When Eclipse creates an executable JAR it places nested JAR file within it and adds a special classloader to load the nested JAR files. If one of the nested JARs contains the properties and pictures, then mist likely that classloader code is having problems. Of course, that could be related to how you access the properties and pictures (I do hope that you are using one of the load as resource methods.)

Personally, I would not do this. I always use Maven (or at times Ant) to build my projects. I would either package all of the JARs I need in a lib directory and provide a script that sets the classpath accordingly. Or if I wanted an all-in-one JAR file, I would extract the contents of all required JARs and include their contents in my JAR (thus no nested JARs and no need to a special classloader). Both of these are easily accomplished with Maven and Ant.
Randy Miller
Ranch Hand

Joined: Feb 13, 2012
Posts: 44
Hi Peter!

So, I fixed this problem myself
Ain´t that difficult if you once find out how it works.
Just to answer your question: YES, I used an EXTRA folder for the images like this: projectname/src/images/some.jpg
Basically to get this one done with eclipse, first you create an executable jar just as you normally would.
Then, you use WinRar to open a view on the jar structure and manipulate it afterwards WITHOUT unpacking and repacking it again.
I just added the wanted folder "images" to the bin folder inside the jar and there it was: The perfect executable jar

Thanks for your help
Dan Foster
Greenhorn

Joined: May 02, 2013
Posts: 21
Hi Randy,

Did you create the bin folder within the jar file? Because there is no bin folder when a generate a runnable jar.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Eclipse exporting an executable Jar
 
Similar Threads
Exporting to jar file in eclipse
Netbeans jars versus Eclipse jars
Creating .jar files (preferably in Eclipse) and adding existing .jar files to them
Runnable jar is not including the files
Issues deploying Java application