Prog 2 Classpath | Updated |
The programs javac and java are are normally posioned in the directory C:\JDK1.4.2\BIN, when using standard installation. If JDK is installed in another directory or drive you must use this position instead of the above mentioned in autoexec.bat.
Example Windows 9X: Antag at du har lavet 3 packages: pack1, pack2 og pack3 alle anbragt i kataloget mypackages. For at få adgang til klasserne i de tre packages tilføjes flg. linie sidst i filen autoexec.bat:
SET CLASSPATH=%CLASSPATH%;C:\homedirectory\mypackages
Now the Java-compiler will also search in mypackages for packages.
Example Windows 2000 (XP): Assume you have made 3 packages: pack1, pack2 and pack3 all positioned in the directory mypackages. To get access to the classes in these 3 packages choose:
Start menu -> Control panel -> System -> Avanceret
->Miljøvariable
Start -> Settings -> Control Panel -> System
-> Advanced -> Environment Variables
Now a form pops up and it can be filled out with:
Variable Name: classpath
Variable Value: C:\homedirectory\mypackages
Thereafter the Java-compiler will also search in mypackages
for packages and their content.
What is jar ?
Java Archive (jar) is Javas system for compressing (via zip)
and collect .class files in an archive.
By adding the archive-path to the CLASSPATH the Java-compileren can
find the .class filerne.
Later the archive can be extended with more .class filer as well as
.class files can be removed from the archive.
jar has some options e.g.:
c create
new archive
v generate
verbose output on standard output
f specify
archive file name
u update
existing archive
For a complete dexcription se Sun's home pages or give the following
command from the DOS-prompt:
jar
Java's archive system really easy work of systematizing. If e.g. an applet will have to use many files it is great just once and only once to transfer (and remember the name of) the archive file only.
Example: Assume that you have two .class files: my1.class og my2.class and want to save them in the archive myclasses.jar. From the DOS-prompt give the following command:
jar -cvf myclasses.jar my1.class my2.class
Move the archive to an appropriate directory and add the directory-path
to the classpath.
Later the file mynew.class is added by the command:
jar -uvf myclasses.jar mynew.class
As jar saves special Metadata of the classes you cannot just
.zip the files.
A few editors (maybe Netbeans, but not TextPad) offers the jar
faciliteten on projects.