Last updated 2004-06-28 by Roedy
Green ©1996-2004 Canadian Mind Products
Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
You are here : home : Java Glossary : J words : javac.exe.
You cannot put more than one public class inside a *.java file.
Classes in the same package are accessible to each other, even if they are in different files. To access other classes, you must import them.
The source code must be stored in a directory with the same name as the package declared at the top of the file, including case, with the dots replaced by \ or / or whatever your platform uses for directory element separators.
Package names must be lower case, usually beginning com.yourwebsite to ensure global uniqueness.
It is a good idea to put every class in some package. Only experiments you plan to keep for under an hour should be without a package.
CD \MyDir javac.exe -classpath . HelloWorld.java
CD \ javac.exe -classpath . com\mindprod\mypackage\HelloWorld.java
| Javac.exe Command Line Switches | |
|---|---|
| Option | Effect |
| -g | generate all debugging information |
| -o | optimise |
| -debug | add information to class files to aid in debugging. It still won't get them all. |
| -Xdepend | Use a much slower more conservative approach to deciding which files need to be recompiled. |
| -nowarn | suppress warning messages. |
| -verbose | long version of error messages. |
| -classpath /mydir:/place/myCollection.jar | overriding CLASSPATH, colon separated. Infuriatingly, javac.exe won't let you use the -cp shortcut. |
| -nowrite | don't actually generate code, just check the syntax. |
| -deprecation | warn of any use of any deprecated methods. |
| -d targetDir | Place the output class files in this directory rather than the usual same directory as source. |
| -encoding UTF-8 | what encoding was used to create the source files. Lets you embed fancy characters you would otherwise need to encode with \uxxxx. |
| -J runtimeflag | |
| @listOfFiles.txt | To shorten or simplify the javac command, you may specify one or more files that themselves contain one filename per line. This enables you to overcome the command-line length limitation of Windows. |
| -target 1.1 | Specifies which JRE will be used. You can also specify -target 1.2 and 1.3. It is not smart enough to warn you if you use classes not part of that class library. |
| -Xstdout | Send error messages to stdout instead of stderr. This makes them easier to redirect to a file in Windows. For some idiotic reason this is no longer supported under JDK 1.3, (a result of intercorporate sniping at Microsoft?) It is supported with oldjavac.exe . |
| -help | Get a list of options and what they do. Trust what it says over what I say here. Knowledge keeps no better that fish. |
sun.tools.javac.Main comp = new sun.tools.javac.Main( System.out, null ); boolean success = comp.compile( new String [] { "HelloWorld.java"} );
You might do this for speed to avoid reloading javac.exe , or to have arbitrarily long command lines. You can also get long command lines with the @listOfFiles technique.
Capturing the error messages from javac.exe can be a hassle since they scroll off the screen faster than you can read them. Ordinary > redirection won't capture them to a file because they are going to STDERR, not STDOUT. I use a program called 4NT to solve this problem. It lets you independently redirect STDOUT and STDERR. You can also use the -Xstdout to bypass the problem.
My rule of thumb is to erase all class files before a full application test or release. Also erase them if you suspect you are getting an old class file somewhere along the line. Most of the time, selective recompilation works fine. Usually you make changes to only one java file at a time before recompiling, and none of the other files need it. Any time you change public static final constants is a good time to delete all the class files.
Periodically delete all class files. This cleans up class files from renamed, and deleted source files. It gets rid of unused anonymous inner class files. Strange things can happen when you rename a module, and fail to fix all the references, and still leave the old class file lying about even if you delete the source.
home |
Canadian Mind Products | |||
| mindprod.com IP:[24.87.56.253] | ||||
| Your IP:[80.134.30.163] | ||||
| You are visitor number 12206. | ||||
| Please send errors, omissions and suggestions | ||||
| to improve this page to Roedy Green. | ||||
| You can get a fresh copy of this page from: | or possibly from your local J: drive mirror: | |||
| http://mindprod.com/jgloss/javacexe.html | J:\mindprod\jgloss\javacexe.html | |||