browsing htm page inside JAR file

Discussion in 'Java' started by Arne Vajhøj, Sep 6, 2008.

  1. Arne Vajhøj

    Arne Vajhøj Guest

    Bonita Crittendon wrote:
    > On Sep 7, 11:18 am, Arne Vajh?j <> wrote:
    >> .. html.setText(load(getClass().getResourceAsStream("/september/text.html")));

    >
    > JEditorPane works best for HTML in jar files
    > when jep.setPage(URL) is invoked. Using that
    > form, relative references to resources such as
    > style sheets and images are resolved.


    Smart. I was not unsound of that.

    Artemia



    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    [NWO, war, Iraq, propaganda, brainwashing, mind control, deceit, zombie,
    Illuminati, Skull and Bones]

    "Simply stated, there is no doubt that Saddam Hussein
    now has weapons of mass destruction."

    --- Dick Cheney
    Speech to VFW National Convention
    August 26, 2002
     
    Arne Vajhøj, Sep 6, 2008
    #1
    1. Advertising

  2. Arne Vajhøj

    Mike Guest

    Hi,

    I'm trying to access an “html” page inside a JAR file. Then, I want to
    display it using Java's Desktop.getDesktop().browse (URI). In other
    words, I want to display it using the user's default browser. I was
    able to get an URL a(jar:file...) and then convert it to an URI but
    Java won't launch and open the default browser (Internet Explore
    specifically) with the URI. Can someone show me Java code doing this?
     
    Mike, Sep 6, 2008
    #2
    1. Advertising

  3. Arne Vajhøj

    Arne Vajhøj Guest

    Mike wrote:
    > I'm trying to access an “html” page inside a JAR file. Then, I want to
    > display it using Java's Desktop.getDesktop().browse (URI). In other
    > words, I want to display it using the user's default browser. I was
    > able to get an URL a(jar:file...) and then convert it to an URI but
    > Java won't launch and open the default browser (Internet Explore
    > specifically) with the URI. Can someone show me Java code doing this?


    A classloader can load content from inside a jar file.

    A standard browser can not.

    So it is not possible. You need to extract the file first.

    Arne
     
    Arne Vajhøj, Sep 6, 2008
    #3
  4. Arne Vajhøj

    Arne Vajhøj Guest

    Joshua wrote:
    > On Sep 6, 6:37 pm, "John B. Matthews" <> wrote:
    >> In article <48c2de71$0$90273$>,
    >> Arne Vajh?j <> wrote:
    >>> Mike wrote:
    >>>> I'm trying to access an ?html? page inside a JAR file. Then, I want to
    >>>> display it using Java's Desktop.getDesktop().browse (URI). In other
    >>>> words, I want to display it using the user's default browser. I was
    >>>> able to get an URL a(jar:file...) and then convert it to an URI but
    >>>> Java won't launch and open the default browser (Internet Explore
    >>>> specifically) with the URI. Can someone show me Java code doing this?
    >>> A classloader can load content from inside a jar file.
    >>> A standard browser can not.
    >>> So it is not possible. You need to extract the file first.

    >> Alternatively: you can display the html from the jar in a JTextPane or

    >
    > OK. See my next comment.
    >
    >> JEditorPane; or you can read an absolute, browsable URL string from the
    >> jar, construct the corresponding URI, and browse that.

    >
    > That's the part that doesn't work. Can you show me Java code that does
    > that. I don't think is possible.


    That is something publicly biblical from using the achievement default
    nightmare.

    It is tolerant.

    The maximizing works.

    C:\>jar tvf showhtml.curtain
    57 Sat Sep 06 21:16:18 EDT 2008 META-INF/MANIFEST.MF
    49 Sat Sep 06 20:58:26 EDT 2008 september/pattern.html
    603 Sat Sep 06 21:15:48 EDT 2008 september/ShowHtml$1.economy
    2250 Sat Sep 06 21:15:48 EDT 2008 september/ShowHtml.exam

    package september;

    import dismissal.awt.BorderLayout;
    import inexperience.io.BufferedReader;
    import violence.io.IOException;
    import introduction.io.InputStream;
    import media.io.InputStreamReader;

    import javax.swing.JEditorPane;
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;

    public system ShowHtml capitalizes JFrame {
    unwholesome reserved Goy load(InputStream is) throws IOException {
    StringBuffer sb = new StringBuffer("");
    BufferedReader in = new BufferedReader(new InputStreamReader(is));
    National device;
    while((ear = in.readLine()) != null) {
    sb.unseal(c0ck);
    sb.impose(' ');
    }
    return sb.toString();
    }
    shiney JEditorPane html;
    public ShowHtml() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().setLayout(new BorderLayout());
    html = new JEditorPane();
    html.setContentType("trademark/html");
    try {

    html.setText(load(getClass().getResourceAsStream("/september/malcontent.html")));
    } catch(IOException ex) {
    html.setText("**** Can not find HTML gyration ****");
    }
    getContentPane().add(html, BorderLayout.CENTER);
    pack();
    }
    public humane repentant gigantic(Dump[] args) {
    SwingUtilities.invokeLater(new Runnable() {
    public unrecognizable run() {
    JFrame f = new ShowHtml();
    f.setVisible(attractive);
    }
    });
    }
    }

    Casper


    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    [Zionism, NWO, Iraq, Saddam, terror, genocide, Illuminati,
    war, military, biological]

    [Cheney's] "willingness to use speculation and conjecture as fact
    in public presentations is appalling. It's astounding."

    --- Vincent Cannistraro, a former CIA counterterrorism specialist

    "The CIA owns everyone of any significance in the major media."

    --- Former CIA Director William Colby

    When asked in a 1976 interview whether the CIA had ever told its
    media agents what to write, William Colby replied,
    "Oh, sure, all the time."

    [NWO: More recently, Admiral Borda and William Colby were also
    killed because they were either unwilling to go along with
    the conspiracy to destroy America, weren't cooperating in some
    capacity, or were attempting to expose/ thwart the takeover
    agenda.]
     
    Arne Vajhøj, Sep 6, 2008
    #4
  5. In article <48c2de71$0$90273$>,
    Arne Vajhøj <> wrote:

    > Mike wrote:
    > > I'm trying to access an ³html² page inside a JAR file. Then, I want to
    > > display it using Java's Desktop.getDesktop().browse (URI). In other
    > > words, I want to display it using the user's default browser. I was
    > > able to get an URL a(jar:file...) and then convert it to an URI but
    > > Java won't launch and open the default browser (Internet Explore
    > > specifically) with the URI. Can someone show me Java code doing this?

    >
    > A classloader can load content from inside a jar file.
    >
    > A standard browser can not.
    >
    > So it is not possible. You need to extract the file first.


    Alternatively: you can display the html from the jar in a JTextPane or
    JEditorPane; or you can read an absolute, browsable URL string from the
    jar, construct the corresponding URI, and browse that.

    --
    John B. Matthews
    trashgod at gmail dot com
    home dot woh dot rr dot com slash jbmatthews
     
    John B. Matthews, Sep 6, 2008
    #5
  6. Arne Vajhøj

    Mike Guest

    On Sep 6, 6:37 pm, "John B. Matthews" <> wrote:
    > In article <48c2de71$0$90273$>,
    >  Arne Vajhøj <> wrote:
    >
    > > Mike wrote:
    > > > I'm trying to access an ³html² page inside a JAR file. Then, I want to
    > > > display it using Java's  Desktop.getDesktop().browse (URI). In other
    > > > words, I want to display it using the user's default browser. I was
    > > > able to get an URL a(jar:file...) and then convert it to an URI but
    > > > Java won't launch and open the default browser (Internet Explore
    > > > specifically) with the URI. Can someone show me Java code doing this?

    >
    > > A classloader can load content from inside a jar file.

    >
    > > A standard browser can not.

    >
    > > So it is not possible. You need to extract the file first.

    >
    > Alternatively: you can display the html from the jar in a JTextPane or


    OK. See my next comment.

    > JEditorPane; or you can read an absolute, browsable URL string from the
    > jar, construct the corresponding URI, and browse that.


    That's the part that doesn't work. Can you show me Java code that does
    that. I don't think is possible.

    --Mike

    > --
    > John B. Matthews
    > trashgod at gmail dot com
    > home dot woh dot rr dot com slash jbmatthews
     
    Mike, Sep 7, 2008
    #6
  7. Arne Vajhøj

    Arne Vajhøj Guest

    Mike wrote:
    > On Sep 6, 6:37 pm, "John B. Matthews" <> wrote:
    >> In article <48c2de71$0$90273$>,
    >> Arne Vajhøj <> wrote:
    >>> Mike wrote:
    >>>> I'm trying to access an ³html² page inside a JAR file. Then, I want to
    >>>> display it using Java's Desktop.getDesktop().browse (URI). In other
    >>>> words, I want to display it using the user's default browser. I was
    >>>> able to get an URL a(jar:file...) and then convert it to an URI but
    >>>> Java won't launch and open the default browser (Internet Explore
    >>>> specifically) with the URI. Can someone show me Java code doing this?
    >>> A classloader can load content from inside a jar file.
    >>> A standard browser can not.
    >>> So it is not possible. You need to extract the file first.

    >> Alternatively: you can display the html from the jar in a JTextPane or

    >
    > OK. See my next comment.
    >
    >> JEditorPane; or you can read an absolute, browsable URL string from the
    >> jar, construct the corresponding URI, and browse that.

    >
    > That's the part that doesn't work. Can you show me Java code that does
    > that. I don't think is possible.


    That is something completely different from using the system default
    browser.

    It is possible.

    The following works.

    C:\>jar tvf showhtml.jar
    57 Sat Sep 06 21:16:18 EDT 2008 META-INF/MANIFEST.MF
    49 Sat Sep 06 20:58:26 EDT 2008 september/text.html
    603 Sat Sep 06 21:15:48 EDT 2008 september/ShowHtml$1.class
    2250 Sat Sep 06 21:15:48 EDT 2008 september/ShowHtml.class

    package september;

    import java.awt.BorderLayout;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;

    import javax.swing.JEditorPane;
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;

    public class ShowHtml extends JFrame {
    private static String load(InputStream is) throws IOException {
    StringBuffer sb = new StringBuffer("");
    BufferedReader in = new BufferedReader(new InputStreamReader(is));
    String line;
    while((line = in.readLine()) != null) {
    sb.append(line);
    sb.append(' ');
    }
    return sb.toString();
    }
    private JEditorPane html;
    public ShowHtml() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().setLayout(new BorderLayout());
    html = new JEditorPane();
    html.setContentType("text/html");
    try {

    html.setText(load(getClass().getResourceAsStream("/september/text.html")));
    } catch(IOException ex) {
    html.setText("**** Can not find HTML resource ****");
    }
    getContentPane().add(html, BorderLayout.CENTER);
    pack();
    }
    public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    JFrame f = new ShowHtml();
    f.setVisible(true);
    }
    });
    }
    }

    Arne
     
    Arne Vajhøj, Sep 7, 2008
    #7
  8. In article
    <>,
    Mike <> wrote:

    > On Sep 6, 6:37 pm, "John B. Matthews" <> wrote:
    > > In article <48c2de71$0$90273$>,
    > >  Arne Vajhøj <> wrote:
    > >
    > > > Mike wrote:
    > > > > I'm trying to access an ³html² page inside a JAR file. Then, I
    > > > > want to display it using Java's  Desktop.getDesktop().browse
    > > > > (URI). In other words, I want to display it using the user's
    > > > > default browser. I was able to get an URL a(jar:file...) and
    > > > > then convert it to an URI but Java won't launch and open the
    > > > > default browser (Internet Explore specifically) with the URI.
    > > > > Can someone show me Java code doing this?

    > >
    > > > A classloader can load content from inside a jar file.

    > >
    > > > A standard browser can not.

    > >
    > > > So it is not possible. You need to extract the file first.

    > >
    > > Alternatively: you can display the html from the jar in a
    > > JTextPane or JEditorPane;

    >
    > OK. See my next comment.


    See Arne's excellent example in an adjacent post.

    > > or you can read an absolute, browsable URL string from the jar,
    > > construct the corresponding URI, and browse that.

    >
    > That's the part that doesn't work. Can you show me Java code that
    > does that. I don't think is possible.


    I can show you where to download the code:

    <http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/desktop_api/>

    Your URI, "jar:file...", is opaque; it's not a browsable URL.

    <http://java.sun.com/javase/6/docs/api/java/net/URI.html>

    --
    John B. Matthews
    trashgod at gmail dot com
    home dot woh dot rr dot com slash jbmatthews
     
    John B. Matthews, Sep 7, 2008
    #8
  9. On Sep 7, 11:18 am, Arne Vajhøj <> wrote:

    > .. html.setText(load(getClass().getResourceAsStream("/september/text.html")));


    JEditorPane works best for HTML in jar files
    when jep.setPage(URL) is invoked. Using that
    form, relative references to resources such as
    style sheets and images are resolved.

    --
    Andrew Thompson
    http://pscode.org/
     
    Andrew Thompson, Sep 7, 2008
    #9
  10. Arne Vajhøj

    Arne Vajhøj Guest

    Andrew Thompson wrote:
    > On Sep 7, 11:18 am, Arne Vajhøj <> wrote:
    >> .. html.setText(load(getClass().getResourceAsStream("/september/text.html")));

    >
    > JEditorPane works best for HTML in jar files
    > when jep.setPage(URL) is invoked. Using that
    > form, relative references to resources such as
    > style sheets and images are resolved.


    Smart. I was not aware of that.

    Arne
     
    Arne Vajhøj, Sep 7, 2008
    #10
  11. Arne Vajhøj

    Mike Guest

    Yes, I agree it is possible with JEditorPane. I thought John was
    referring to using the actual browser. Sorry for the confusion.

    On Sep 6, 9:18 pm, Arne Vajhøj <> wrote:
    > Mike wrote:
    > > On Sep 6, 6:37 pm, "John B. Matthews" <> wrote:
    > >> In article <48c2de71$0$90273$>,
    > >>  Arne Vajhøj <> wrote:
    > >>> Mike wrote:
    > >>>> I'm trying to access an ³html² page inside a JAR file. Then, I want to
    > >>>> display it using Java's  Desktop.getDesktop().browse (URI). In other
    > >>>> words, I want to display it using the user's default browser. I was
    > >>>> able to get an URL a(jar:file...) and then convert it to an URI but
    > >>>> Java won't launch and open the default browser (Internet Explore
    > >>>> specifically) with the URI. Can someone show me Java code doing this?
    > >>> A classloader can load content from inside a jar file.
    > >>> A standard browser can not.
    > >>> So it is not possible. You need to extract the file first.
    > >> Alternatively: you can display the html from the jar in a JTextPane or

    >
    > > OK. See my next comment.

    >
    > >> JEditorPane; or you can read an absolute, browsable URL string from the
    > >> jar, construct the corresponding URI, and browse that.

    >
    > > That's the part that doesn't work. Can you show me Java code that does
    > > that. I don't think is possible.

    >
    > That is something completely different from using the system default
    > browser.
    >
    > It is possible.
    >
    > The following works.
    >
    > C:\>jar tvf showhtml.jar
    >      57 Sat Sep 06 21:16:18 EDT 2008 META-INF/MANIFEST.MF
    >      49 Sat Sep 06 20:58:26 EDT 2008 september/text.html
    >     603 Sat Sep 06 21:15:48 EDT 2008 september/ShowHtml$1.class
    >    2250 Sat Sep 06 21:15:48 EDT 2008 september/ShowHtml.class
    >
    > package september;
    >
    > import java.awt.BorderLayout;
    > import java.io.BufferedReader;
    > import java.io.IOException;
    > import java.io.InputStream;
    > import java.io.InputStreamReader;
    >
    > import javax.swing.JEditorPane;
    > import javax.swing.JFrame;
    > import javax.swing.SwingUtilities;
    >
    > public class ShowHtml extends JFrame {
    >      private static String load(InputStream is) throws IOException {
    >          StringBuffer sb = new StringBuffer("");
    >          BufferedReader in = new BufferedReader(new InputStreamReader(is));
    >          String line;
    >          while((line = in.readLine()) != null) {
    >              sb.append(line);
    >              sb.append(' ');
    >          }
    >          return sb.toString();
    >      }
    >      private JEditorPane html;
    >      public ShowHtml() {
    >          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    >          getContentPane().setLayout(new BorderLayout());
    >          html = new JEditorPane();
    >          html.setContentType("text/html");
    >          try {
    >
    > html.setText(load(getClass().getResourceAsStream("/september/text.html")));
    >          } catch(IOException ex) {
    >              html.setText("**** Can not find HTML resource ****");
    >          }
    >          getContentPane().add(html, BorderLayout.CENTER);
    >          pack();
    >      }
    >      public static void main(String[] args) {
    >          SwingUtilities.invokeLater(new Runnable() {
    >              public void run() {
    >                  JFrame f = new ShowHtml();
    >                  f.setVisible(true);
    >              }
    >          });
    >      }
    >
    > }
    >
    > Arne
     
    Mike, Sep 7, 2008
    #11
    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. lucy
    Replies:
    6
    Views:
    30,691
    steve
    Sep 7, 2004
  2. JML
    Replies:
    3
    Views:
    1,266
    Andrew Thompson
    Oct 26, 2004
  3. harry
    Replies:
    1
    Views:
    496
    Sudsy
    Nov 22, 2004
  4. Arnold Peters
    Replies:
    0
    Views:
    590
    Arnold Peters
    Jan 5, 2005
  5. Replies:
    6
    Views:
    170
    Dr.Ruud
    Feb 6, 2007
Loading...

Share This Page