Back to the main page

Compilation and Deployment

Classpath

Java has Bootstrap classes e.g. rt.jar found under jre/lib, Extension classes e.g. sunjce_provider.jar (cryptography) found under jre/lib/ext and Application classes.

Only application classes need to be specified in a classpath.


Setting the classpath

default
(no classpath specified)
Searches in the current directory and subdirectories in the case of packages
set the $CLASSPATH variableOverrides default
java -cp or -classpathOverrides default and $CLASSPATH
java -jarOverrides all other options.
Class-Path: jar1.jar jar2.jar
can be set in the manifest to refer to classes outside the main.jar

javac and javadoc can specify -sourcepath to limit the search for source files to only the specified sourcefile path.


jar - Java ARchive

jar options

ccreate
foutput to file named ...
vverbose
minclude manifest information from file ...
The supplied file must be UTF-8 and end with a newline/carriage return.
(META-INF/MANIFEST.MF is created regardless)
0turn off compression
Callows a directory's contents to be jar'd into a different directory
tlists (table of) contents
xextract, this will overwrite any existing files
uupdate, add or replace files or update the manifest
eset entry point, overrides the manifest Main-Class



Contents of MANIFEST.MF

    Manifest-Version: 1.0
     // Automatically added

    Created-By: 1.7.0_06 (Oracle Corporation)
     // JDK version, automatically added

    Main-Class: classname

    Class-Path: directory/MyUtils.jar

    Name: name of specification
    Specification-Title: title
    Specification-Version: version
    Specification-Vendor: vendor

    Name: name of implementation
    Implementation-Title: title
    Implementation-Version: version
    Implementation-Vendor: vendor

    Name: directory/packageName
    Sealed: true
     // Can be repeated
     // If only Sealed: without preceding Name: then all packages are sealed


Jarsigner

Overwrites a jar with signed jar.

A signed jar contains a signature file XXX.SF. Each file, including the manifest has a SHA1-Digest: generated.

Signed jar files invoked by java -jar will be verified at runtime, or we can call jarsigner -verify myJar.jar.

jarsigner -keystore XXX
          -storepass XXX
          -keypass XXX
          myJar.jar
          alias


A keystore can hold several private keys, each of them aliased.

> find .
.
./a
./a/b
./a/b/App.class

> jar cf myJar.jar -C a .

> find .
.
./a
./a/b
./a/b/App.class
./myJar.jar

> jar tf myJar.jar
META-INF/
META-INF/MANIFEST.MF
b/
b/App.class



JNLP

Java Network Launch Protocol file

<?xml version="1.0" encoding="utf-16"?>
<jnlp>
  <information>
    <file>...</file>
    <vendor>...</vendor>
  </information>
  <resources>
    <j2se version="..." max-heap-size="..."/>
    <property name="..." value="..."/>
    <jar href="..." download="eager"/>
    <jar href="..." download="lazy"/>
  </resources>
  <application-desc>
    <argument>...</argument>
  </application-desc>
  <security>
    <all-permission/>
  </security>
</jnlp>