Java Reference
In-Depth Information
This represents a high-level under-
standing of how Java executes an appli-
cation from a
JAR
file. But this high-level
view conceals a few implicit decisions
made by standard
JAR
file handling, such
as these:
JVM start
Read
Main-Class
manifest entry
Jar?
Yes
Found?
Load main class
Where to search inside the
JAR
file
for a requested class
■
No
Yes
Success
Which internal classes should be
externally exposed
■
No
Call public static
void main (String [])
With respect to the first decision, a
JAR
file has an implicit policy of searching all
directories relative to the root of the
JAR
file as if they were package names corre-
sponding to the requested class (for
example, the class
org.foo.Bar
is in
org/foo/Bar.class
inside the
JAR
file).
With respect to the second decision,
JAR
files have an implicit policy of exposing
all classes in root-relative packages to all
requesters. This is a highly decon-
structed view of the behavior of
JAR
files,
but it helps to illustrate the implicit mod-
ularity decisions of standard
JAR
files.
These implicit code-visibility decisions
are put into effect when you place a
JAR
file on the class path for execution.
While executing, the
JVM
finds all
needed classes by searching the class
path, as shown in figure 2.10. But what is
the exact purpose of the class path with
respect to modularity? The class path
defines which external classes are visible
to the
JAR
file's internal classes. Every
class reachable on the class path is visible
to the application classes, even if they
aren't needed.
With this view of how standard
JAR
files and the class path mechanism work,
let's look into the details of how
OSG
i
handles these same code-visibility con-
cepts, which is quite a bit different. We'll
No
Yes
Non-daemon
threads?
Wait
Figure 2.9
Flow diagram showing the steps the
JVM goes through to execute a Java program from
the class path
Find class
Is
loaded?
Next class path
entry
No
More
class path
entries
No
Yes
No
Search class path
entry
Contains
.class
Yes
Return class
Define class
Figure 2.10
Flow diagram showing the steps the
JVM goes through to load a class from the class path