< Zurück | Inhalt | Weiter >

7.4.1 Compiling FetchURL with gcj

We’ll discuss gcj’s command-line switches in detail in Section 7.5, but we will have to use a couple of them here. First off, be aware that since gcj is actually part of gcc, all of the non-language-specific switches of that system also work in gcj; thus, -o specifies the name of the binary output file, and so on. There are many references on gcc to which you should refer for details (the manpage on gcc is a good place to start). Example 7.1 shows compiling and running FetchURL with gcj.


8. http://www.gnu.org/software/classpath/

9. The gcj and GNU Classpath projects are in the middle of an effort to merge their libraries into a common library. The GNU Classpath project aims to be a Free Software replacement for the JRE API JAR file. As such, it is meant to be a library of Java bytecodes that may be used as a drop-in replacement in any Java runtime environment. For our discussion, we will assume you are using libgcj as shipped with gcj itself.

10. http://gcc.gnu.org/java/jdk14-libgcj.php


The source code for FetchURL can be found in Example 3.30.



Example 7.1 Compiling and running FetchURL with gcj

$ gcj -o furl --main=FetchURL FetchURL.java

$ ./furl http://www.multitool.net/pubkey.php http://www.multitool.net/pubkey.php:




<TITLE>Michael Schwarz's Public GPG key</TITLE>




<H1>Michael Schwarz's Public GPG Key</H1>




Version: GnuPG v1.0.7 (GNU/Linux)

mQGiBDuv6IQRBACn1TIWUXiEuZtfR+0Lqx6tYBAzIRpljL42O6r5nKHmndsWV71e FUnhQpQIf+bNGGPMEt0g0vFpD6YWKP4uIEh2o+u1iyIIMs5QH3iqp8kFjbtVZa21






We already explained the -o switch which names the resulting binary. The other switch we use here is --main which specifies the class containing the main() that should be run when the binary is invoked. Remember that every Java class may contain a main(). In a multiclass program, the binary needs to know which main() to run when the binary is executed.

Remember that FetchURL is in the default package,11 so you simply type the class name as the argument to --main. However, if the class is in a nondefault package, the fully qualified name must be used.


11. Any class without a package declaration is in the default package.