Wednesday, June 23, 2010

'java' Command

Description

Execute Java classes/applications

Technical Specification (partial)

    java [-options] class [args...] (to execute a class) or java [-options] -jar jarfile [args...]
-Dmyprop=myval set a system property. retrieval: System.getProperty("myprop");

Notes

  • Classpath Searching:
    1. JRE
    2. Environment Variable (classpath)
    3. Command-Line Classpath (overrides environment variable)
  • Directory Delimitor: unix '/', Mac '/', Windows '\'
  • Classpath Separator: unix ':', Mac ':', Windows ';'
  • Current Directory: '.'
  • First class found is the one used. Searching stops when first class is found.

Examples

bash script

javac -d build -sourcepath src src/com/bryanpugh/scjp/MyClass.java

ant

    <project basedir=".">
      <target name="">
        <mkdir dir="${basedir}/build"/> <javac srcdir="${basedir}/src" destdir="${basedir}/build"/>
      </target name="">
    </project>

Monday, June 21, 2010

'javac' Command

Description

Compile java files.

Technical Specification (partial)

javac [options] [sourcefiles]
  • -cp or -classpath path - ':' or ';' separated list of locations to search for source files
  • -sourcepath path - ':' or ';' separated list of location to search for classes, interfaces, etc
  • -d directory - the destination for .class files
    • does not create target directory
    • does create package path directories

Notes

  • Classpath Searching:
    1. JRE
    2. Environment Variable (classpath)
    3. Command-Line Classpath (overrides environment variable)
  • Directory Delimitor: unix '/', Mac '/', Windows '\'
  • Classpath Separator: unix ':', Mac ':', Windows ';'
  • Current Directory: '.'
  • First class found is the one used. Searching stops when first class is found.

Examples

bash script

    javac -d build -sourcepath src src/com/bryanpugh/scjp/MyClass.java

ant

    <project basedir=".">
      <target name="compile">
        <mkdir dir="build"/> <javac srcdir="src" destdir="build"/>
      </target name="compile">
    </project>