Can I use GCJ instead of the Sun JDK for a project?

You can try. GCJ seems solid enough, and GNU Classpath is far from complete but making interesting progress. Here's what seems to work on Fedora Core 4 Linux anyway:

1. Make sure you have the right RPMs installed:

$ rpm -ql java-1.4.2-gcj-compat-devel libgcj

You might in fact have things installed in paths like


which will be nice but is not necessary.

2. Using Tools > Java Platform Manager, create a new Java Platform using the correct "JDK home". For example,/usrmay work, or try/usr/lib/jvm/java-1.4.2-gcjif it does not. If you like, you can add sources from http://www.gnu.org/software/classpath/ or just use asrc.zipfrom a Sun (or other vendor's) JDK 1.4 installation.

3. Make a plain Java project. You can try Samples > General > GUI Form Examples to see Swing (sort of) working. Anagram Game does not work yet (some Swing text handling error).

4. In the Properties dialog for the project, under Libraries, select GNU libgcj 4.0.2 ... as the Java Platform. If asked, accept the 1.4 source level rather than 1.5.

(It seems that currently the GNU compiler actually handles JDK 5 source constructs but the Classpath runtime does not support JDK 5 language features yet, so it's not too useful to try to use generics. Classpath 1.19 for the first time has a generics "preview" build, so it may be available for general use soon.)

5. That should be it - build and run your project as usual. Add-showversionto Run > VM Options in project properties if you don't believe it. Generate Javadoc works too! No debugging support, sorry.

Note that this setup builds regular Java bytecode and runs it using an interpreter. If you want to play with building native code and running the program that way, you may need some custom targets inbuild.xmland you may have difficulties with subprojects or libraries - but if you get it working please edit this page with instructions!

Tip: you can also use Matisse (Free Design) on AWT-based forms! And using the GCJ runtime, the AWT peers will be GTK, so it will look like a Gnome application - though of course the widget set is very limited.

Applies to: NetBeans 5.0 (maybe 4.1 and 4.0?)

Platforms: Linux (maybe other Unix, maybe Windows under Cygwin)

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo