by Margrit Höhme, 2002 (java@mhoehme.de)

About JarBrowser

The JAR browser is a very simple browser. It shows how to access a web site packed into a jar file. A JAR browser can be handy as a custom help for a Java application: The help files can be packaged as a single JAR.

The main features of the JAR browser are:

  1. a simple browser based on javax.swing.JFrame, using javax.swing.JEditorPane and javax.swing.text.html.HTMLEditorKit
  2. a simple javax.swing.event.HyperLinkListener
  3. a well-formed URL to a JAR file

The URL to a JAR file

The Java API for java.net.URL.openConnection() says:

If for the URL's protocol (such as HTTP or JAR), there exists a public, specialized URLConnection subclass belonging to one of the following packages or one of their subpackages: java.lang, java.io, java.util, java.net, the connection returned will be of that subclass. For example, for HTTP an HttpURLConnection will be returned, and for JAR a JarURLConnection will be returned.
An example for an URL to a JAR file can be found in the Java API for java.net.JarURLConnection:
This also works with local JAR files:
(Pay attention to the slashes and to the exclamation mark!)

The JAR browser works fine with any kind of relative hyperlinks. The web site may contain images as well as subdirectories.

Source Code

source code

Last modified: