home *** CD-ROM | disk | FTP | other *** search
- Java Runtime Environment
-
- Information
-
- 5/21/97
-
-
- 1.0 Introduction
- 2.0 Using the JRE 1.1.1
- 3.0 Questions and Answers
-
-
-
- 1.0 Introduction
-
- The Java Runtime Environment (also known as the Java Runtime
- or JRE) consists of the Java Virtual Machine, Java Core
- Classes, and supporting files. It is the runtime part of the
- JDK--no compiler, no debugger, no tools. It is the smallest
- set of executables and files that form the standard Java
- Platform. This product satisfies the demands for the smallest
- runtime to be bundled with Java applications.
-
-
-
- 2.0 Using the JRE 1.1.1
-
-
- The JRE provides three built-in places to put classes, as
- shown in the following diagram.
-
- <runtime-dir>
- _________________|________________
- | | |
- bin lib classes
- | ____|____ |
- | | *.class
- | |
- rt.jar classes.jar
-
-
- lib/rt.jar Java runtime core classes provided by Sun
-
- lib/classes.jar Vendor-defined classes in jar format
-
- classes/*.classes Vendor-defined individual .class files
-
-
- 2.1 Setting Up the JRE with an Application
-
- The following steps are necessary to set up the JRE 1.1.1
- with an application:
-
- 1. Install JRE in its own subdirectory (referred to here
- as <runtime-dir>). Include all the the required files
- listed above in the bin and lib subdirectories of
- <runtime-dir>, following the same directory hierarchy
- and relative placement of files (the default classpath
- depends on this). The internationalization files
- marked as optional can be included for non-native
- language support.
-
- 2. Place all application-specific classes either as
- individual .class files in the classes directory or
- zipped in a file at lib/classes.jar.
-
- Both locations are automatically included in the
- default runtime class path, so they will be found
- even if you do not explicitly set the CLASSPATH
- environment variable. The file classes.jar can be
- created using the JAR tool included with JDK 1.1 or
- any PKZIP-compatible ZIP archiving tool that
- supports DEFLATE compression, such as InfoZIP or
- WinZIP.
-
- 3. If native code support is required, the native library
- must be located in LD_LIBRARY_PATH on Solaris or the
- executable search PATH on Win32. The best way to do
- this is to install the native libraries in either
- <runtime-dir>/lib/<sys> on Solaris or <runtime-
- dir>\bin on Win32.
-
- 4. If installing a pure Java application, use the runtime
- executable program (<runtime-dir>\bin\java.exe on
- Windows or <runtime-dir>/bin/java on Solaris) to
- invoke the application's main class. For example:
-
- <runtime-dir>/bin/java <app-main>
-
- For applications that require the invocation API to
- start the Java runtime, it is necessary to write a
- custom C wrapper that uses the JNI invocation API.
-
-
-
- 2.2 Creating and Bundling a Java Application on Top of JRE
-
- The following is an extended example of how to create and
- bundle a simple Java application which runs on top of a
- JRE included with it.
-
- It is worthwhile to note the directory structure of JRE
- components. The structure of the JRE is intentionally
- almost identical to that of the JDK (with some files
- missing and a few files renamed). The intention is to
- allow for a simple, seamless transition from developing
- an application with the JDK to deploying it with the more
- lightweight JRE.
-
-
- 1. Develop an application.
-
- Developing an application requires a copy of the
- JDK, or some other development tool. Our example
- application is a simple GUI, jre.demo.HelloWorld.
- The HelloWorld.java source is included.
-
- To invoke the example, change to the "bin"
- directory and execute "hello".
-
- 2. From the JRE Download Page, download the JRE for each
- platform you intend to deploy on.
-
-
- 3. Compile into shareable Native libraries.
-
- Should your application require native methods, you
- should first compile these into a shareable native
- library specific to your target
- platform/architecture.
-
- Our example program has a simple native method to
- illustrate the point. These Solaris and Win32
- Makefiles demonstrate how this compilation might be
- done. (Here is the source for the JNI-style native
- method. On win32, once you have built a .DLL, it
- should be placed in the $(JRE_TOP)\bin directory
- (next to all the java runtime's dll's). On Solaris,
- your .SO should be placed in the
- $(JRE_TOP)/lib/$(ARCH)/$(THREADS_TYPE)
- subdirectory, where $(ARCH) denotes the target
- architecture (for this example, the architecture is
- "sparc") and $(THREADS_TYPE) is the type of threads
- the Solaris VM is using (for now, this must be
- "green_threads").
-
- In the example programs, you'll see files called
- $(JRE_TOP)\bin\HelloWorld.dll on Win32 and
- $(JRE_TOP)/lib/sparc/green_threads/HelloWorld.so on
- Solaris. Make sure the names of your native
- libraries do not overwrite any of the JRE's native
- libraries.
-
-
- 4. Build a platform-specific executable.
-
- Your application needs some kind of starting point,
- a simple program that is the first thing the end
- user executes. This program, in turn, invokes the
- public static void main(String[] argv) method of
- your Java class.
-
- On Windows, if you have access to a C compiler
- during development, a small C program is the best
- way to do this. The sample program, hello.c, will
- do nicely. You can compile this with a macro
- defining JAVA_ARGS to be the name of your Java
- class that defines main(String[] argv). An added
- benefit of using a small C program like this one on
- Windows is that, when compiled with DWINMAIN, you
- can have a purely Windows application (that is, one
- that does not pop up a console when started by
- double-clicking on the desktop), if it is GUI-
- based.
-
- On UNIX, a wrapper Korn-shell script like this can
- be used to invoke the Java interpreter on your main
- class.
-
-
- These Makefiles for Win32 and Solaris were used to
- build the example programs. Both these simple
- wrapper programs should be located in the
- $(JRE_TOP)/bin directory. These wrappers look very
- much like the wrappers that invoke the Java
- interpreter in the JDK. However, there's one main
- difference you should note, described in the
- following paragraphs.
-
- Both the wrappers make sure to unset the CLASSPATH
- and JAVA_HOME environment variables before invoking
- the interpreter. These variables can be convenient
- while doing development on top of the JDK, but they
- can cause trouble when your application is
- installed on a user's machine. The reason is
- simple: There might be several Java applications
- installed on that machine. If a user has installed
- a Java development tool that modified the
- AUTOEXEC.BAT or .login script, then CLASSPATH and
- JAVA_HOME might point at a JDK1.0.2-based java
- runtime.
-
- If these environment variables are left intact when
- the Java interpreter is invoked, then it pulls
- 1.0.2 classes. If you rely on 1.1 features, your
- program fails in serious ways. Worse, it's unlikely
- that the classes for your app will even be found in
- that CLASSPATH. Unsetting CLASSPATH and JAVA_HOME
- before invoking the JRE interpreter sanitizes your
- application against unpredictable results.
-
- The default CLASSPATH used by the JRE is:
-
- $(JRE_TOP)/lib/rt.jar:$(JRE_TOP)/lib/i18n.jar:$(JRE
- _TOP)/lib/
-
- classes.jar:$(JRE_TOP)/lib/classes.zip:$(JRE_TOP)/c
- lasses
-
- where the variable $(JRE_TOP) is defined to be the
- directory where the JRE is installed (it has bin
- and lib directories underneath it). rt.jar and
- i18n.jar are used to hold the runtime's (required)
- core classes and (optional) internationalization
- classes, so it is recommended that you store the
- classes specific to your application either in
- $(JRE_TOP)/lib/classes.jar or else as individual
- class files in the $(JRE_TOP)/classes subdirectory.
-
-
- 5. Build, test, and ship.
-
- Once you have built your wrapper executables and
- put them in the (JRE_TOP)/bin subdirectory, your
- application should be ready.
-
- As with any software product, a final round of
- testing is advisable, now that your program has
- taken its finished form atop the JRE.
-
-
-
- 3.0 Questions and Answers
-
- Question: How should my application find other
- resources, such as images, sounds, and other files,
- when it runs on top of the JRE? Where should I store
- these things?
-
- Answer: Running the JDK's interpreter, you can always
- find the top directory where the JDK is installed from
- Java by:
-
- String javaHome = System.getProperty("java.home");
- /** This is the runtime directory path to the top
- of where * the Java runtime is installed. It has
- the bin and lib * directories underneath it. */
-
-
- The mechanism is identical when your application is
- running on top of the JRE. In fact, our sample
- application HelloWorld.java uses this mechanism at
- runtime to find the image it displays. The image is
- stored in the lib directory below $(JRE_TOP) (or
- $(JAVA_HOME); the two are equivalent):
-
- void loadImage() throws IOException {
- URL imgURL;
-
- String jh = System.getProperty("java.home");
- String file = jh + File.separator+"lib"+
- File.separator+"smooch.gif";
- imgURL = new URL("file", "", file);
- ....
- }
-
-
- As an aside, the lib subdirectory is the usual place
- to store and find such resources--as long as the file
- names don't collide with any of the files already
- there in the JRE.
-
-
-
-