LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-15-2009, 01:22 AM   #1
Mridulj
Member
 
Registered: Jan 2008
Posts: 49

Rep: Reputation: 15
error in running java


I have installed jdk 1.6 .when I compile file (java)
it compiles creating a class file but when I use the
java command it gives errors .

$javac ArraySortSearch.java (compiles successfully : no errors)

$java ArraySortSearch

Exception in thread "main" java.lang.NoClassDefFoundError: while resolving class: ArraySortSearch
at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
at java.lang.Class.initializeClass() (/usr/lib/libgcj.so.5.0.0)
at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0)
at java.lang.Class.forName(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
at gnu.gcj.runtime.FirstThread.run() (/usr/lib/libgcj.so.5.0.0)
at _Jv_ThreadRun(java.lang.Thread) (/usr/lib/libgcj.so.5.0.0)
at _Jv_RunMain(java.lang.Class, byte const, int, byte const, boolean) (/usr/lib/libgcj.so.5.0.0)
at __gcj_personality_v0 (/root/Desktop/java.version=1.4.2)
at __libc_start_main (/lib/tls/libc-2.3.4.so)
at _Jv_RegisterClasses (/root/Desktop/java.version=1.4.2)
Caused by: java.lang.ClassNotFoundException: java.lang.StringBuilder not found in [file:/usr/share/java/libgcj-3.4.6.jar, file:./, core:/]
at java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
at gnu.gcj.runtime.VMClassLoader.findClass(java.lang.String) (/usr/lib/libgcj.so.5.0.0)
at java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib/libgcj.so.5.0.0)
at _Jv_FindClass(_Jv_Utf8Const, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0)
at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/libgcj.so.5.0.0)
at _Jv_BytecodeVerifier.verify_instructions_0() (/usr/lib/libgcj.so.5.0.0)
at _Jv_VerifyMethod(_Jv_InterpMethod) (/usr/lib/libgcj.so.5.0.0)
at _Jv_PrepareClass(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
at _Jv_WaitForState(java.lang.Class, int) (/usr/lib/libgcj.so.5.0.0)
at java.lang.VMClassLoader.linkClass0(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
...9 more
 
Old 04-15-2009, 01:35 AM   #2
jay73
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 133Reputation: 133
That message indicates you are not running jdk but gcj. The latter contains only a selection of the classes that were introduced in java 1.5 so it often causes compilation errors if code contains references to any of those newer classes.

Last edited by jay73; 04-15-2009 at 01:36 AM.
 
Old 04-15-2009, 08:57 AM   #3
Mridulj
Member
 
Registered: Jan 2008
Posts: 49

Original Poster
Rep: Reputation: 15
I am using JDK since I have compiled using javac and afterthat
used java command.
 
Old 04-15-2009, 12:33 PM   #4
jay73
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 133Reputation: 133
No, you are not. GCJ uses the java and javac commands, too, so that does not say much. Look at the details of the error messages instead to find out; it's "gcj" all over.
 
Old 04-15-2009, 01:17 PM   #5
Mridulj
Member
 
Registered: Jan 2008
Posts: 49

Original Poster
Rep: Reputation: 15
then how do i use the jdk to compile my java programs and
then run them .
 
Old 04-15-2009, 01:26 PM   #6
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
Which distro are you using? If it's Debian or one of it's offspring, then you could use update-alternatives:
Code:
update-alternatives --config javac
So long as the JDK is installed somewhere where the alternatives system can find it, you can select it from a menu. If not, you will probably find that javac is a symbolic link to the actual program - just modify the link to point to the version from the JDK.
 
Old 04-15-2009, 01:35 PM   #7
Mridulj
Member
 
Registered: Jan 2008
Posts: 49

Original Poster
Rep: Reputation: 15
I am using RHEL4 .

how do I modify the link to point to the version from the JDK so
that I can use javac and java
 
Old 04-15-2009, 03:00 PM   #8
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
You could do it like this:
Code:
$ which javac #find out where it is
/usr/bin/javac
$ file java # check that it really is a link
/usr/bin/javac: symbolic link to '/path/to/gcj/javac'
$ rm /usr/bin/javac # remove the link
$ ln -s /path/to/jdk/javac /usr/bin/javac # recreate it
The last two steps would need to be done as root (or using sudo). If file tells you that javac is actually the executable file, rather than a link, you should either remove gcj using yum, rather than rm'ing javac:
Code:
yum remove gcj # I believe, not so used to yum yet
... to avoid causing problems with the package management system, or create a symbolic link to javac in a directory that appears in the $PATH environment variable before /usr/bin (or wherever javac is located). For instance,
Code:
rob:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/rob/scripts
... shows me that /usr/local/bin appears before /usr/bin, so I could make a link to javac there, and it would take precedence over the link in /usr/bin:
Code:
$ ln -s /path/to/jdk/javac /usr/local/bin/javac
You'll probably want to do likewise for java as well (and definitely if you remove gcj).

Last edited by Robhogg; 04-15-2009 at 03:13 PM.
 
Old 04-15-2009, 05:54 PM   #9
jay73
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 133Reputation: 133
Well, you can always install openJDK from the fedora repositories. It is an open source implementation of the Sun JDK and it is available in RPM format.

Frankly, RHEL is about the worst choice you can make if you need to run the Sun JDK. To my knowledge, it is one the few distros that has made a point of refusing to include that type of software. Sure, it can be made to work but why bother - and although good as a basic solution, Robhogg's solution does not explain how to get the other thirty or so JDK executables to work or how to switch from one JDK to another one. And removing gcj is only feasible if you do not install Eclipse; if I remember well, it is one of its dependencies.

Last edited by jay73; 04-15-2009 at 05:58 PM.
 
Old 04-16-2009, 12:13 PM   #10
Mridulj
Member
 
Registered: Jan 2008
Posts: 49

Original Poster
Rep: Reputation: 15
is it possible to install openJDK from the fedora repositories
in RHEL 4 .
 
Old 04-16-2009, 03:56 PM   #11
jay73
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 133Reputation: 133
I don't use RHEL so I can't tell. I believe that Red Hat has its own repositories for subscribers. In addition, there are a number of third party repositories, for example:
http://jpackage.org/
If you follow their instructions, you can install the Sun JDK. Jpackage has many java related package but - for licensing reasons - they require you to get the JDK directly from Sun, then you can use one of their packages to make installing it easier.
Then there is also
http://dag.wieers.com/rpm/packages.php
Many other packages there but it appears that the openJDK is not included.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
error running java application alee Linux - Newbie 2 02-09-2009 12:29 AM
Error running java gamor Linux - Newbie 4 06-01-2007 01:50 AM
java This.class error when running Fredstar Programming 2 02-12-2006 11:48 PM
error running soapstone (java) networking benchmark celejar Linux - Software 0 03-05-2005 07:21 PM
error in running a java app in linux milo36472 Linux - Newbie 16 02-09-2005 11:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration