Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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.
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.
$ 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,
... 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).
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.