天天看点

about javac

javac(compile.execute)]

javac <options> <source>

what i will say is the important options which a java programer should know.

-verbose :show the process of compiling which is a good thing for realizing the java's compiling.

an example of show:

[parsing started /home/zvin/desktop/Hello.java]

[parsing completed 18ms]

[search path for source files: /home/zvin/desktop]

[search path for class files: /usr/lib/jvm/java-6-sun-1.6.0.15/jre/lib/resources.jar,/usr/lib/jvm/java-6-sun-1.6.0.15/jre/lib/rt.jar,/usr/lib/jvm/java-6-sun-1.6.0.15/jre/lib/sunrsasign.jar,/usr/lib/jvm/java-6-sun-1.6.0.15/jre/lib/jsse.jar,/usr/lib/jvm/java-6-sun-1.6.0.15/jre/lib/jce.jar,/usr/lib/jvm/java-6-sun-1.6.0.15/jre/lib/charsets.jar,/usr/lib/jvm/java-6-sun-1.6.0.15/jre/classes,/usr/lib/jvm/java-6-sun-1.6.0.15/jre/lib/ext/sunjce_provider.jar,/usr/lib/jvm/java-6-sun-1.6.0.15/jre/lib/ext/localedata.jar,/usr/lib/jvm/java-6-sun-1.6.0.15/jre/lib/ext/dnsns.jar,/usr/lib/jvm/java-6-sun-1.6.0.15/jre/lib/ext/sunpkcs11.jar,/home/zvin/desktop]

[loading /home/zvin/desktop/test2/Test.class]

[loading java/lang/Object.class(java/lang:Object.class)]

[loading java/lang/String.class(java/lang:String.class)]

[checking test1.Hello]

[loading java/lang/System.class(java/lang:System.class)]

[loading java/io/PrintStream.class(java/io:PrintStream.class)]

[loading java/io/FilterOutputStream.class(java/io:FilterOutputStream.class)]

[loading java/io/OutputStream.class(java/io:OutputStream.class)]

[wrote /home/zvin/desktop/Hello.class]

[total 165ms]

-classpath||-cp <path> :specify the path where the *.class files or annotation that compiling source.java needs

note:the <path> don't include the package path(use /usr/home/zvin rather than /usr/home/zvin/java/lang/String.class).

an example:

javac -classpath /usr/home/zvin HelloWorld.java

-sourcepath <path> :specify the path of source java files which compiling needs.

note:the source java files found to help compile will also be compiling that you can understand if you known the principle of java's compile.

note:the <path> don't include the package path(use /usr/home/zvin rather than /usr/home/zvin/java/lang/String.java).

an example:javac -sourcepath /usr/home/zvin/desktop /home/zvin/HelloWorld.java

-d <directory> :specify the directory where you want your generated class files exit

note:if you don't use -d option,compiler will put generated class files defautly where your source java file is in without the package path.

so,use -d option is quite successary.

finally,a better simple javac command should like this:javac -classpath <path> -d <directory> <source>