I am developing a swing app in eclipse. So far it runs well in eclipse, but am having weird problems when it is jarred.
The part that works is getting background images. The are in package view.images.backgrounds.
To get them as a list so users can choose one I have:
f = new File(getClass().getResource("images/backgrounds").toURI());
//get a String[] of file names and return.
In eclipse this path is reported as:
file:/home/david/projects/client/bin/view/images/backgrounds/
When it is jarred it is:
file:/home/david/Documents/client/view/images/backgrounds/
Even though the package view.images.backgrounds is in the jar, it didn't work until I dropped then in a folder at view/images/backgrounds/. I am not sure why but that is perfect since end users could drop in any image they want to without fuss.
I did the same for a serialized file holding settings information. I need to read and write to it, but not doing the same thing as the images(put them in packages) results in not being able to save settings via jar file. So it is in package view.data and named settings.ser.
It works great inside eclipse, but when I jar it up I get this error: Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: URI is not hierarchical
The path reported when running in the jar file is file:/home/david/Documents/client/client.jar!/view/data/settings.ser which is definitely not what I need. For some reason this time client.jar is in the path, but it is not for the images.
Obviously, I need to read and write to that file, what do i need to do to get it to work while jarred?
The offending line is: ois = new ObjectInputStream(new FileInputStream(new File(tmp.getClass().getResource("data/settings.ser").toURI()))); which is run in a class in the view package.