javac used to compile source files (*.java)
Source for Hello.java
javac [-options] filesjava used to run a compiled code (*.class)
java [-options] class [args...]jar used to archive files into JAR (*.jar)
jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] filesIn practise:
Source for Hello.java
package com.blogspot.programmerutilities; public class Hello { public static void main (String[] args){ System.out.println("Hello World!"); } }Location of the file:
\src\com\blogspot\programmerutilities\Hello.javaDirectory structure:
-src -com -blogspot -programmerutilities -Hello.java -buildCompile source file using javac (-d option points to a directory where compiled files will be placed)
javac -d build \src\com\blogspot\programmerutilities\Hello.javaAfter compilation a Hello.class file will be placed in \build directory (and subdirectories accordingly to the package name).
-src -com -blogspot -programmerutilities -Hello.java -build -com -blogspot -programmerutilities -Hello.classTo start this application go to \build (the directory directly above the outer directory of the package) and run java tool with a full name of the class (package and class name without an extension)
cd build java com.blogspot.programmerutilities.Hello // Prints "Hello World!"To create java archive (JAR) run jar tool with a name of new created archive (hello.jar) and the most outer directory of the package name (com)
jar -cf hello.jar comAfter that in \build directory the hello.jar file will be placed
-src -com -blogspot -programmerutilities -Hello.java -build -com -blogspot -programmerutilities -Hello.class -hello.jarTo check the content of the jar run jar tool with -tf options (table of content and file name)
jar -tf hello.jarTo start an application using a jar file run java tool with -cp (or -classpath) option with a path to a jar and full name of a class
java -cp /build/hello.jar com.blogspot.programmerutilities.Hello // Prints "Hello World!"
Comments
Post a Comment