I have a small application that I have been working on for several months. It works great. Now when I created an executable .jar file for it, it will not load data from a .csv file. I have tried looking into everything I can think if. I checked file paths, etc. I am using OpenCVS to read the csv. Is there an issue with that when you include it into another .jar file? I am trying to log if there is an error but I don't even get an error. I just doesn't run past that statement...any ideas would be greatly appreciated.
App Directory
|-- Data (xml file that will be created when the .csv actually loads. Can write .txt file here fine)
|-- Logs (can write here fine)
|-- Out (other output files)
|-- the .csv data file to load
|-- the .jar file
Okay, then you're going to have to provide the complete path to the CSV file to be able to open it. You say it's "in the file system"... is it in any special place, like the user's home directory or something? I don't know what "App Directory" means in your diagram.
Also, what's the current working directory when you run the code from the jar file? You might be able to locate the CSV file relative to that.
How are you trying to open the file?
Can you show the code related to OpenCSV being pointed at this file?
Note that when dealing with an application, it normally uses the "Working Directory" to resolve files from.
More often than not this is the Windows "User" folder or similar rather than the directory where the application jar file is installed.
So you can either
- move the data file to the working directory
- specify the full path to your data file (will have to be configured in some way)
- find a way to put the file on the classpath and retrieve it via getResourceAsStream()
For clarification, the .jar and the .csv are in the exact same directory. I will look at some of these suggestions today, but if you have any more, please let me know.
I don't think it is the spaces as I tried generically without them and it runs fine when not running the .jar file.
I got some logging in place for when I am running the .jar version and the full path to the file is not there. That must be the issue. Why would the relative path work when running it via the command line but not as a .jar?
Okay, I don't think it has anything to do with the files or paths. It is the CSVReader itself. If I comment out the reading it will create the txt and xml data files just fine. It is in the reading in of the data. The full file path is there and correct.
Is is in the way the opencsv-2.3.jar is being used by my .jar?
Well, if it can't find the file then you'll have got an exception.
If CSVReader couldn't read the file (for whatever reason) then you'll have got an exception.
Assuming your manifest file contains the correct classpath and stuff, the jar creation looks fine.
The link you provided, the poster got a UnsupportedClassVersionError, is that what you got? Yet I doubt that's the problem for you. OpenCSV 2.3 at least uses Java 6 so the java version is correct.
Thanks for all the help! I think I finally got it. I had to add the classpath to the mainfest file and then include the lib directory in the app directory that will be distributed.
You're welcome, though I think I provided the least help. You did manage to answer the questions and keep providing information (), which is why the whole thing was sorted out.
Post by:autobot
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
a bit of art, as a gift, that will fit in a stocking