• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with Eclipse exporting an executable Jar

 
Randy Miller
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Randy Miller
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You answered my second and third question, but didn't answer the first one.
 
Randy Miller
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Randy,

Did you create the bin folder within the jar file? Because there is no bin folder when a generate a runnable jar.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic