0

My program runs exactly as it should when I run it out of eclipse, but when I try to build it into a runnable jar I get problems.

When I set Library Handling to Extract required libraries into generated JAR, or Copy required libraries into a sub-folder next to the generated JAR, the program runs but doesn't do anything that involves the external libraries. When I set it to Package required libraries into generated JAR, absolutely nothing happens when I try to run the JAR.

At this point I have no idea what to do after spending the past hour looking online for solutions, library handling seems to work fine for everyone else?

I'm using eclipse 4.4.1 if it makes a difference

Simon K
  • 1
  • 3
  • How are you running the jar? If done from a command window, do you get any error output? – Thomas Apr 20 '15 at 18:11
  • I'm just double clicking the .jar file, so there's nowhere to output errors – Simon K Apr 20 '15 at 18:12
  • You may be losing error messages. Try running in a commandline with `java -jar ` – Thomas Apr 20 '15 at 18:14
  • [This](http://gyazo.com/bbd7cb78b3019ab23b94900fe2db5855) is what I'm getting, this is with packaging the libraries by the way – Simon K Apr 20 '15 at 18:16
  • You can also have your reference files packaged along with the jar if you place them in your bin folder. That way you won't have to ensure that the reference files are present everywhere you move your jar file. – CSCH Apr 20 '15 at 18:18
  • Possibly try one of the solutions from [this question](http://stackoverflow.com/questions/4881136/runnable-jar-file-generated-by-eclipse-wont-execute) – Thomas Apr 20 '15 at 18:21
  • Placing the files in my bin folder didn't change anything – Simon K Apr 20 '15 at 18:23
  • So building to a different location seems to have fixed the problem somehow, but thank you for your help! – Simon K Apr 20 '15 at 18:38

1 Answers1

0

First check to make sure you have the libraries. To do so open up the jar file with win rar or something similar. If the libraries are missing you can just copy and paste them into the jar file.

If they are there then you can create a batch file (If using windows) to run your jar file with the java command. Doing this will give you a console in command prompt to view output and stack-traces. This can help you find where the problem is. Command for .bat file:

java -jar jarfile.jar

If you don't want to create a batch file and run it from command prompt, remember to make the cmd path the same as the jar file location.

Forseth11
  • 1,418
  • 1
  • 12
  • 21
  • So I tried copying the libraries into the jar and it didn't fix the problem. I instead tried exporting to a folder higher in the hierarchy because it seemed like a file not found exception was cut off. However, it ended up running perfectly. I think the problem I might have had was with the folder names it was stored in or something? In any case it's working now, but thanks for you're help! – Simon K Apr 20 '15 at 18:38