• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with Jar file  RSS feed

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So this .csv file... where is it located? In the file system? Inside the jar?
 
Stephanie Challand
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the file system. Something like:

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

The .jar and the .csv are in the same directory.
 
Paul Clapham
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1840
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()

 
Stephanie Challand
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! Here is the code.

 
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags (←click this) when posting code, it makes it much easier to read. I've done it for you this time.
 
Stephanie Challand
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for fixing that. Sorry!

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.
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am wondering if having spaces in the file name is messing you up. Try:

 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried a file chooser to find the CSV file?
 
Stephanie Challand
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using it. The location is correct. I am not sure where the issue is. Everything works perfectly when not compiled and run from the .jar.
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about the manifest? Are the "Main-Class" and "Class-Path" properties set correctly?

Henry
 
Stephanie Challand
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the .jar runs fine. It just cannot access the files or something like that as it won't load the data...still looking into things.
 
Stephanie Challand
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Stephanie Challand
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Saloon Keeper
Posts: 18800
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I recommend using the getAbsolutePath() method when reporting a "file not found" or similar error.

That way you know what directory it's looking in for the file.
 
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

So...how are you handling exceptions?
 
Paul Clapham
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephanie Challand wrote:Is is in the way the opencsv-2.3.jar is being used by my .jar?


It could be. However I don't think you told us yet how you set your classpath while running your jar file.
 
Stephanie Challand
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is how I am building the .jar file



The openCSV.jar is in the /lib directory when I am building my .jar.

I also found this, that sounds very similar: http://www.java-forums.org/new-java/85801-problem-opencsv-when-creating-jar-file.html, but I am not sure how to fix things if that even is the issue.
 
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stephanie Challand
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Success After all that trying.
 
Stephanie Challand
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Thanks for all the help. Java is not my forte. Just working on a project for a small organization.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!