The moose likes Linux / UNIX and the fly likes How to compile hello world in eclipse? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "How to compile hello world in eclipse?" Watch "How to compile hello world in eclipse?" New topic

How to compile hello world in eclipse?

Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 381
I notice my fedore core 4 has eclipse allready installed and compiled. I also notice that I have gcj installed instead of sun java.

When I tried to compile a trivial hello world java program, I get the a stack trace (see below). I noticed that JAVA_HOME was not defined so I did "export JAVA_HOME=/usr/bin" which is where it seemed to be.

However, I know java (gcj) is working correctly because the following works:

[siegfried@localhost hello_java]$ pwd
[siegfried@localhost hello_java]$ javac hello/world/HelloWorld.java
[siegfried@localhost hello_java]$ java hello.world.HelloWorld
all done

Unfortunately, defining JAVA_HOME did not help. Can someone tell me what is wrong?


Here is the stack trace from eclipse when I try to execute my simple java program:
Exception in thread "main" java.lang.NoClassDefFoundError: while resolving class: hello.world.HelloWorld
at java.lang.VMClassLoader.transformException(java.lang.Class, java.lang.Throwable) (/usr/lib64/libgcj.so.6.0.0)
at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib64/libgcj.so.6.0.0)
at java.lang.Class.initializeClass() (/usr/lib64/libgcj.so.6.0.0)
at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib64/libgcj.so.6.0.0)
at gnu.java.lang.MainThread.run() (/usr/lib64/libgcj.so.6.0.0)
Caused by: java.lang.ClassNotFoundException: java.lang.StringBuilder not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:/home/siegfried/workspace/hello_java/,file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib64/libgcj.so.6.0.0)
at java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib64/libgcj.so.6.0.0)
at java.lang.ClassLoader.loadClass(java.lang.String) (/usr/lib64/libgcj.so.6.0.0)
at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib64/libgcj.so.6.0.0)
...4 more
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

My $JAVA_HOME contains these:
, most of them being directories, including 'bin', which in turn includes java, javac and ...

Perhaps java is a symbolic link you may follow, to find the location where all that stuff is located.

If you like to use java-1.5 features, which is quiet common, you will have to get rid - at least disable - the blackdown-java-stuff, and get the sun-JDK.

Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 381
I was not aware that JAVA_HOME was like PATH in the sense it could contain multiple entries. Are these entries to be seperated by ":" like they are in PATH?

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15947

JAVA_HOME points to the root directory of the JDK.

I personally find the "alternatives" system to be a royal pain when working with Java. But in any event, I don't think that the gcj system is complete enough to run Eclipse. I recomend downloading a Sun (or IBM) jdk, installing it, and pointing JAVA_HOME at the installed Java.

Customer surveys are for companies who didn't pay proper attention to begin with.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Sorry, Siegfried.
The JAVA_HOME variable points to the directory containing the listed files and directory.

might help getting rid of the default values.
Read the man-page for update-alternatives to get the details.
[ November 16, 2005: Message edited by: Stefan Wagner ]
I agree. Here's the link: http://aspose.com/file-tools
subject: How to compile hello world in eclipse?
Similar Threads
java.lang.NoClass DefFoundError: while resolving class
System.out.println("i -->"+i); This statement give runtime error on linux
JMS TopicConnection Factory
Classpath problem?
Running a simple java program