Results 1 to 4 of 4
Thread: Resouce not found in jar
- 08-23-2013, 01:31 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 17
- Rep Power
- 0
Resouce not found in jar
I have an application with one single package (default package) whose resources can be found in the 'src' netbeans directory. I can run my application within netbeans with no issue at all. But my application fails when I run it from a jar file built by Netbeans. The below statement does not work.
String fullname = getClass().getResource("/reportMAIN.jrxml").getFile();
fullname = org.apache.commons.lang.StringUtils.replace(fullna me,"%20"," "); //to remove special characters
JasperDesign jasperDesign = JRXmlLoader.load(fullname); //this triggers the below error
The above statement triggers the following error:
Error occurred: java.io.FileNotFoundException: file:\C:\Documents and Settings\J
OHN\My Documents\NetBeansProjects\HMR_52\dist\HMR_52.jar! \reportMAIN.jrxml (The
filename, directory name, or volume label syntax is incorrect)
Notice the '!' character in the above file name.
However, JVM successfully finds pictures used by my application such as:
jBZoomIn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/zoom_in.png"))); //works
The above picture is in the jar main root (and Netbeans src folder) as 'reportMAIN.jrxml'. Additionally, I do not have to remove special characters as in 'reportMAIN.jrxml' ("%20")
Can anybody explain to me what is going on? Why is JVM failing to find "reportMAIN.jrxml"?
- 08-23-2013, 06:47 AM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,638
- Rep Power
- 13
Re: Resouce not found in jar
Take that full file path, create a File object from it, and try to either read from it or check it exists. The question becomes: does
file:\C:\Documents and Settings\JOHN\My Documents\NetBeansProjects\HMR_52\dist\HMR_52.jar! \reportMAIN.jrxml
exist if you try to create a File object from that path? (note difference between a URL and File, one of which the API you are using relies upon)
- 08-24-2013, 11:05 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 17
- Rep Power
- 0
Re: Resouce not found in jar
Hi!
Thanks for your reply.
Sorry but I do not understand what you mean. Let me rephrase my question. Maybe this can help you or somebody else. How can I access a resource in jar when my main class and said resource are in such a jar and the jar has no subdirectories? getClass().getResource("/reportMAIN.jrxml").getFile() is not working for me.
Thanks
- 08-24-2013, 11:20 PM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,638
- Rep Power
- 13
Similar Threads
-
A4J is not found
By aali-01 in forum Web FrameworksReplies: 0Last Post: 02-17-2011, 05:53 AM -
JAD NOT FOUND !! hlp
By ganero in forum CLDC and MIDPReplies: 1Last Post: 01-17-2011, 05:09 AM -
404 Not Found
By mary in forum Java ServletReplies: 5Last Post: 11-07-2007, 10:15 AM
Bookmarks