Results 1 to 4 of 4
  1. #1
    JOHNINALBANY is offline Member
    Join Date
    Nov 2010
    Posts
    17
    Rep Power
    0

    Default 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"?

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default 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)

  3. #3
    JOHNINALBANY is offline Member
    Join Date
    Nov 2010
    Posts
    17
    Rep Power
    0

    Default 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

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: Resouce not found in jar

    The JRXmlLoader class has a load method that accepts an InputStream, try calling this method passing the returned value from getResourceAsStream() method for the Class object

Similar Threads

  1. A4J is not found
    By aali-01 in forum Web Frameworks
    Replies: 0
    Last Post: 02-17-2011, 06:53 AM
  2. JAD NOT FOUND !! hlp
    By ganero in forum CLDC and MIDP
    Replies: 1
    Last Post: 01-17-2011, 06:09 AM
  3. 404 Not Found
    By mary in forum Java Servlet
    Replies: 5
    Last Post: 11-07-2007, 11:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •