0

The program work fine in eclipse, and I want to make it into an executable, so the user can just click on the exe file. But first i have to make it into a .jar. But it would not run in the .jar file, i try it in the terminal and it gives me this error, im not sure what the errors are because the program runs fine in eclipse.

the errors are

C:\User\Mondi\Desktop\exe>java -jar RunGUI.jar
java.io.FileNotFoundException: airport.txt <??????????>
      at java.io.FileInputStream.open<Native Method>
      at java.io.FileInputStrem.<init><unknown source>
      at java.util.scanner.<init><unknown source>
      at dijkstra.FileProcess.loadtegMap<FileProcess.java:51>
      at dijkstra.RunGUI.main<RunGUI.java:13>
iluxa
  • 6,941
  • 18
  • 36
mon999
  • 15
  • 5
  • According to that trace, it can't find the file "airport.txt." – Maggy May Apr 30 '13 at 00:58
  • so you have airport.txt stuffed in jar? – Satya Apr 30 '13 at 00:59
  • 1
    Look here, perhaps it'll help: http://stackoverflow.com/questions/574809/load-a-resource-contained-in-a-jar – iluxa Apr 30 '13 at 00:59
  • i have actually tried to put the .txt file in every folder i can within the package but still gives me the same error... – mon999 Apr 30 '13 at 01:00
  • Its looking for the file in *current directory*, do you have it in `C:\User\Mondi\Desktop\exe`? If it's in the jar, you need to load it as a resource like @iluxa says – Miserable Variable Apr 30 '13 at 01:02
  • @MiserableVariable Oh, so it has to be in the current directory, it WORKS now, i thought it just has to be inside the .jar file...THANK YOU SO MUCH for all of your answers!! – mon999 Apr 30 '13 at 01:09

2 Answers2

0

If you are trying to open the airport.txt file with no path, it will look for it in the working directory - which is not a directory inside the jar.

You need to look into getResourceAsStream in order to read a file in a jar.

Jason
  • 11,744
  • 3
  • 42
  • 46
0

As I wrote in my comment, the file has to be in current directory for the code as written to find it.

Is that how you want it to be? If airport.txt is a fixed file the perhaps you should add it in the jar along with the compiled code. If it is in the root directory of the jar, you would use getResourceAsStream, which you can then wrap in a Scanner

Miserable Variable
  • 28,432
  • 15
  • 72
  • 133