Distributed as jar files. As extensive as Java's library is, there are sometimes other packages that you want to use. These are almost universally distributed as .jar files. You can access them if you import them.
Where to put predefined .jar files so that the compiler and JRE can find them
A .jar file is basically a .zip file plus a little extra information, the manifest. The jar file may contain one or more packages. Both the compiler and the JRE (Java Runtime Environment) must know where to look for these other jars that you've imported. There are several alternatives.
Modify the CLASSPATH variable to include the jar file
See CLASSPATH.
Tell the compiler or IDE where it is
The compiler (javac command) and JRE (java command) have parameters that specify where to find additional jar files.
Most IDEs have a way to specify where external jar files are located. See NetBeans.
Put the jar file in the JRE lib/ext directory
[Avoid - fragile] This directory is automatically searched by the compiler and runtime systems for needed packages. In my Windows installation of Java, the JRE is installed twice, once with the JDK and once so I put it in both. I don't know that both are actually used, but I didn't want to take any chances.
C:\Program Files\Java\jre1.6.0\lib\ext\
C:\Program Files\Java\jdk1.6.0\jre\lib\ext\
search topic
Tuesday, November 20, 2007
Using other packages
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment