Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to read html inside a jar ?

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to read html inside a jar ?

    Hello,

    I don't manage to read html code from my java application, both nested in a runnable jar.

    I tried this:

    ********************************
    ...
    String indexName = "index.html";
    URL address = getClass().getResource(indexName);
    String filePath=address.toString();
    JFrame viewerFrameInputFile = new DocumentViewer(filePath);
    }

    with DocumentViewer being the well-known class extending JFrame
    and using

    JEditorPane viewer = new JEditorPane ();
    viewer.setPage (new URL (filePath));


    ********************************

    The problem is that the html code is loaded but is not interpreted as such ...


    When using the same program, outside the runnable jar, all is ok.
    Thus, the problem seems that setPage is unable to set the proper
    contentType when the HTML page is put into the jar.

    Does anyone experienced reading html code from a jar ?
    Thanks in advance !!!
    Eric


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,298
    My Mood
    Hungover
    Thanks
    142
    Thanked 620 Times in 531 Posts

    Default Re: How to read html inside a jar ?

    Without seeing an SSCCE and your project setup, this is just a guess, but I would do this:

    getClass().getClassLoader().getResource(indexName) ;

    Instead of this:

    getClass().getResource(indexName);
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to read html inside a jar ? [solution]

    Thank you for your reply.
    Unfortunately, I tried this, this didn't work either.
    However, meanwhile, I have found a solution:

    - using Eclipse, choose export/Runnable JAR file/ and then select
    "Extract required libraries into generated JAR" and not
    (as I did ...) "Package required libraries into generated JAR" !

    - of course, tell eclipse where to find the html files (through Build Path/Add Class Folder)

    and then it is ok with:
    URL address = getClass().getResource(indexName);
    String filePath=address.toString();
    JFrame viewerFrameInputFile = new DocumentViewer(filePath);

    I don't know exactly what Eclipse changed in building the archive,
    but it is ok now !

    Thanks again.
    Eric

Similar Threads

  1. run jar file inside a jar file?
    By ufrubnuckle in forum Java Theory & Questions
    Replies: 1
    Last Post: February 21st, 2013, 05:58 AM
  2. GUI program to edit classes inside a jar file?
    By supercain in forum Java Theory & Questions
    Replies: 1
    Last Post: January 31st, 2013, 07:24 AM
  3. html inside applet?
    By macko in forum Java Theory & Questions
    Replies: 2
    Last Post: July 20th, 2012, 08:39 PM
  4. Hoe do I read html from the web?
    By bholzer in forum Other Programming Languages
    Replies: 2
    Last Post: August 9th, 2011, 06:09 PM