Results 1 to 14 of 14
  1. #1
    3ammary is offline Member
    Join Date
    Jan 2011
    Posts
    14
    Rep Power
    0

    Angry load pdf from jar file (help please)

    hello ,,, i have problem please ,,, it is illustrated in the picture ,,, please help me if you can ,, thanks alot



    //================================================== ========================
    public void doOpen(String name) {
    URL url=getClass().getResource(name);
    try {
    URI uri=null;
    uri=url.toURI();
    File file =new File(uri);
    openFile(file);}
    catch (Exception ex) {}}
    //================================================== ========================
    Last edited by 3ammary; 07-29-2011 at 07:04 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    Wow.
    That has to be a contender for the Least Amount Of Useful Information In An OP award...

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,575
    Rep Power
    23

    Default

    To read "files" from a jar file you can use the getResource() method to get a URL to read. Or getResourceAsStream to get a stream.

  4. #4
    3ammary is offline Member
    Join Date
    Jan 2011
    Posts
    14
    Rep Power
    0

    Default method

    i use this method and still got same problem


    //================================================== ========================
    public void doOpen(String name) {
    URL url=getClass().getResource(name);
    try {
    URI uri=null;
    uri=url.toURI();
    File file =new File(uri);
    openFile(file);}
    catch (Exception ex) {}}
    //================================================== ========================

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,575
    Rep Power
    23

    Default

    still got same problem
    Please post the full text of the error messages.

    What does the openFile() method do?

    The resource is not a file. It is part of a jar file.

    For debugging, print out the values of the variables: url and uri

  6. #6
    3ammary is offline Member
    Join Date
    Jan 2011
    Posts
    14
    Rep Power
    0

    Default

    no error it just don't open the pdf when the jar file is created....
    =====================
    com.​sun.​pdfview.​PDFViewer
    public void openFile(File file) throws IOException

    Open a specific pdf file. Creates a DocumentInfo from the file, and opens that.
    Note: Mapping the file locks the file until the PDFFile is closed.
    Parameters:
    file - the file to open
    Throws:
    IOException
    ======================
    com.​sun.​pdfview.​PDFViewer
    public void openFile(URL url) throws IOException
    open a URL to a PDF file. The file is read in and processed with an in-memory buffer.
    Parameters:
    url
    Throws:
    IOException
    ====================
    The resource is not a file. It is part of a jar file.====>yes it is
    ==================
    url and ur ,, i print them after i converted them to string
    file:/C:/onecopy/pdf%20viewr+zip%20code/build/classes/com/sun/pdfview/1.pdf
    file:/C:/onecopy/pdf%20viewr+zip%20code/build/classes/com/sun/pdfview/1.pdf
    ==================
    the problem is here
    http://hostphotoshere.com/data/4d0/4...90baf31e7a.jpg

  7. #7
    3ammary is offline Member
    Join Date
    Jan 2011
    Posts
    14
    Rep Power
    0

    Default

    waiting for help , thanks alot

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,575
    Rep Power
    23

    Default

    Please explain the contents of the jar file and what you are are going to do when you are able to read the bytes of the pdf "file" that is in the jar file.
    What program is trying to read the contents of the jar file? Is that program's class file in the jar file or outside of it?
    If the program that is trying to read the jar file is not in the jar file, then you need to use the ZipFile or JarFile class to get to the contents of a jar file.

    Were the URL and URI you printed from executing the program that is contained in the jar file?

  9. #9
    3ammary is offline Member
    Join Date
    Jan 2011
    Posts
    14
    Rep Power
    0

    Default

    i am uploading the whole project

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,575
    Rep Power
    23

    Default

    I have no idea what you are trying to do. Why use a jar file? Why not put all the files into a zip file or a rar file?
    What does "uploading" mean? I understand uploading to mean copying a file from a pc to a website. Is that it?

    Please explain the contents of the jar file and what you are are going to do when you are able to read the bytes of the pdf "file" that is in the jar file.
    What program is trying to read the contents of the jar file? Is that program's class file in the jar file or outside of it?

  11. #11
    3ammary is offline Member
    Join Date
    Jan 2011
    Posts
    14
    Rep Power
    0

    Default

    dear norm ,
    the program is pdf reader ,,,
    i want the pdf reader and the pdf file i want to read are in one file ,,, (jar) file ,,, i don't want the pdf alone and the jar file of the reader alone ,, so i want when i open the jar file ,,, it opens the reader file and the pdf file is loaded automatically ...the problem is it runs perfect when it is in netbeans ,, but when i create jar file ,,, it runs only the reader (without automatic loading ) the pdf ,,,, the whole project is here ....
    a.rar
    thanks alot ,,, waiting for your reply

  12. #12
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,575
    Rep Power
    23

    Default

    If the 'pdf reader' is not a java class, then I have no idea how it can read a "file" that is in a jar file.
    If it is a java class, what methods does it have for reading the bytes of the pdf file? The pdf reader needs to be able to read the bytes from an InputStream. The InputStream is returned by the getResourceAsStream method

  13. #13
    3ammary is offline Member
    Join Date
    Jan 2011
    Posts
    14
    Rep Power
    0

    Default

    i have uploaded the whole file ,, could you please take alook of it,if you are free, thanks alot

  14. #14
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,575
    Rep Power
    23

    Default

    If you need help with your code, please make a SSCCE to show your problem and post it here on the forum.
    You need to read the following and respond to it. It may not be possible for your idea to work.

    If the 'pdf reader' is not a java class, then I have no idea how it can read a "file" that is in a jar file.
    If it is a java class, what methods does it have for reading the bytes of the pdf file? The pdf reader needs to be able to read the bytes from an InputStream. The InputStream is returned by the getResourceAsStream method

Similar Threads

  1. Load RDF file
    By priyam_maheshwari in forum Advanced Java
    Replies: 2
    Last Post: 06-27-2011, 10:54 PM
  2. Load file with a lot or lines.
    By juamd in forum Advanced Java
    Replies: 9
    Last Post: 04-26-2011, 07:41 PM
  3. file load
    By myka in forum Advanced Java
    Replies: 1
    Last Post: 04-03-2010, 08:42 PM
  4. Load file in GUI instead of notepad
    By Kruptein in forum AWT / Swing
    Replies: 1
    Last Post: 08-08-2009, 05:57 PM
  5. Not able to load a properties file
    By Happy9959 in forum New To Java
    Replies: 12
    Last Post: 07-29-2008, 07: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
  •