Problem using Jar file

Discussion in 'Java' started by smita bhopale via JavaKB.com, May 31, 2005.

  1. I have one prblem related with using jar files.
    I have created one jar file of my application.In my application I am
    loading web browser & showing html pages which resides in another directory
    other than where my application.class file resides.

    while creating jar file i have used following command
    jar cvmf Manifest.txt name.jar directory[which includes html pages]
    In jar file it is not creating resource folder.

    In source file I have used
    editor.setPage(getClass().getResource("/directoryname/filename.htm"));
    //works

    Jar file includes directory ,but If I run jar file it is throwing
    IOException at run-time that
    Page could not be loaded :Invalid URL

    What should I used so that the code will work fine.

    --
    Message posted via http://www.javakb.com
    smita bhopale via JavaKB.com, May 31, 2005
    #1
    1. Advertising

  2. On Tue, 31 May 2005 07:16:25 GMT, smita bhopale via JavaKB.com wrote:

    > In source file I have used
    > editor.setPage(getClass().getResource("/directoryname/filename.htm"));
    > //works
    >
    > Jar file includes directory ,but If I run jar file it is throwing
    > IOException at run-time that
    > Page could not be loaded :Invalid URL
    >
    > What should I used so that the code will work fine.


    Improve your debugging techniques for starters.

    What is the exact string returned by ..
    getClass().getResource("/directoryname/filename.htm")
    ?

    And more importantly, why did you feed it directly to editor.setPage()
    when things are not working? First principle of debugging is to
    prove exactly what *is* happening. The first part of that is to
    discover the exact URL that call is returning - use System.out.println()
    to dump it to standard out.

    And as an aside, there is another group better able to help
    people starting in Java, more details here..
    <http://www.physci.org/codes/javafaq.jsp#cljh>

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.LensEscapes.com/ Images that escape the mundane
    Andrew Thompson, Jun 1, 2005
    #2
    1. Advertising

  3. If I print using System.out.println(getClass().getResource
    ("/directoryname/filename.htm"));

    It is printing the exact url that I want.

    If I run the code using java classname then it is working fine.But for the
    same class if I create a jar file.After runnint that jar file actully I got
    an error that-
    IOException:page could not be loaded :Invalid URL

    --
    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200506/1
    smita bhopale via JavaKB.com, Jun 3, 2005
    #3
  4. On Fri, 03 Jun 2005 09:19:26 GMT, smita bhopale via JavaKB.com wrote:

    Please include a little of the words you are replying to smita,
    so that someone who has missed the earlier posts might understand
    what is happening.

    > If I print using System.out.println(getClass().getResource
    > ("/directoryname/filename.htm"));
    >
    > It is printing the exact url that I want.


    (shakes head sadly) I did not ask if 'the' URL was 'what you want',
    I asked ..

    "What is the exact string returned by ..
    getClass().getResource("/directoryname/filename.htm")
    ?"

    The reason I ask is that the string should be different for the
    jarred and unjarred versions.

    So, to repeat, (and expand), can you give us the *exact* printout,
    letter for letter, that prints for the two versions.

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.LensEscapes.com/ Images that escape the mundane
    Andrew Thompson, Jun 3, 2005
    #4
  5. Hello Andrew Thompson ,

    Using-
    System.out.println(getClass().getResource("/sc/default1.htm"))---printing:
    following string-
    file:/c:/try/sc/default1.htm

    It is working with java classname command.
    But if I create a jar file for the same class then it is not working.
    How can I solve this problem,please write me.

    --
    Message posted via http://www.javakb.com
    smita bhopale via JavaKB.com, Jun 6, 2005
    #5
  6. On Mon, 06 Jun 2005 06:05:30 GMT, smita bhopale via JavaKB.com wrote:

    > Using-
    > System.out.println(getClass().getResource("/sc/default1.htm"))---printing:
    > following string-
    > file:/c:/try/sc/default1.htm


    This is wrong.

    The call to get resource is not finding the version of the 'default1.htm'
    inside any jar file, but as a separate file on the local filesystem.
    You might try moving the jar to a different location before running it.

    BTW - is that string really 'file:/c:/..', or 'file:/C:/..' (drive letter
    as capital/upper case letter)?

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.LensEscapes.com/ Images that escape the mundane
    Andrew Thompson, Jun 6, 2005
    #6
  7. Yes.You are right.
    It is actually printing:

    file:/C:/try/sc/default1.htm

    If I move the jar to other location it is not working.
    But what should I use so that on running jar file it work fine.
    Which statement I should include?
    Please write me.

    --
    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200506/1
    smita b via JavaKB.com, Jun 6, 2005
    #7
  8. On Mon, 06 Jun 2005 14:02:39 GMT, smita b via JavaKB.com wrote:

    > Yes.You are right.


    (By saying enough things) I often am.

    > It is actually printing:
    >
    > file:/C:/try/sc/default1.htm


    Aha! I want to pause for a moment, now that I have *finally*
    managed to get you to copy/paste exactly what you are seeing,
    to savour the moment. ..OK, done.

    > If I move the jar to other location it is not working.


    Now.. I want to know *exactly* what the same string is for the
    jar, this is more tricky, since System.out.println() can be dumped
    to a 'black hole' for some jar files. You might need to resort
    to showing it in a JTextArea (so you can copy it) in a JOptionPane.

    By the way. Did you say this file was included *inside* the
    jar file? I recall you said you added the directory to the
    jar, but just check that using the jar 'list' option. E.G.

    jar t jarname.jar

    > But what should I use so that on running jar file it work fine.
    > Which statement I should include?
    > Please write me.


    Please *stop* saying that! I do not 'write you' but
    'write the group'. And note that anyone else is also
    free to 'write the group', not just me and you.

    ...and perhaps I should explain that you are accessing a
    usenet newsgroup through a web page at JavaKB. I am not
    (*we* are not) a part of the JavaKB site, but just a person
    who reads this newsgroup.

    Hope that helps.

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.LensEscapes.com/ Images that escape the mundane
    Andrew Thompson, Jun 6, 2005
    #8
  9. smita bhopale via JavaKB.com, Jun 8, 2005
    #9
  10. Andrew Thompson, Jun 8, 2005
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arnold Peters
    Replies:
    0
    Views:
    567
    Arnold Peters
    Jan 5, 2005
  2. muttley
    Replies:
    0
    Views:
    2,718
    muttley
    Oct 20, 2005
  3. cyberco
    Replies:
    4
    Views:
    3,754
    Roedy Green
    Feb 14, 2006
  4. Arnold Peters
    Replies:
    0
    Views:
    657
    Arnold Peters
    Jan 5, 2005
  5. markspace
    Replies:
    2
    Views:
    475
    markspace
    Oct 7, 2011
Loading...

Share This Page