I am pretty new to Java. I have made plenty of programs that run in the safety of Eclipse, but I am having trouble getting a program that I made to function correctly outside of an IDE in JAR form.
Before I get to the real questions, I'll provide some background. I wrote a program that searches a .txt
file roster for a resident in an apartment, an upon selecting the resident, the program allows the user to add the residents to a mail list and for that mail list to be generated into an Excel (.xls
) file via FileOutputStream
and the Apache POI HSSF API. The program is complete with a Swing GUI implemented in NetBeans. In Eclipse, I have my roster, Roster.txt
inside my project folder in the directory with my src and libraries. In order to read the .txt
file, I use the Scanner
class i.e. Scanner scan = new Scanner(new File("Roster.txt"));
.
All of this works perfectly in Eclipse: I can add/remove residents from the mail list and generate .xls
files into my project folder. However, once I try and export the project as a JAR, all functionality disappears. I select File->Export->Runnable JAR File, and the JAR pops up on my desktop just like it's supposed to. When I click the file, the GUI loads up perfectly, and all of the Swing components seem to be working just fine; but when I search a name, no results show up. This leads me to believe that the Roster.txt
file is not being correctly read into my sorting class after the JAR is created.
Is there any part of creating a JAR that messes standard Java I/O? Should I be using args[]
? How would implementing that differ from just using the scanner class to make a new (new File("Roster.txt")
)?