LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-10-2006, 08:55 PM   #1
Klogg
LQ Newbie
 
Registered: Feb 2006
Distribution: Fedora Core 5
Posts: 18

Rep: Reputation: 0
Java won't work!


Hey,

I've installed JDK 1.5.0, and I can't get it to work completely. I got the "javac" command to work right, but when I try to run my programs by typing "java whatever", it says it's missing a bunch of classes or something. I went and asked the teacher's assistants at my university about it, and they said I probably needed to set the classpath in my .bashrc file to something, but they didn't know what I needed to set it to. I also emailed my professor, and he said that he wasn't able to help me either. Which makes me wonder... how in the world do all these people program in Java on their computers without even knowing how to get it installed? Anyway, I've been researching this and trying all sorts of things, but I can't get it to work. I even messed something up and almost had to reinstall Linux. Any help would be appreciated, as I am getting very frustrated. Thanks.
 
Old 02-10-2006, 10:02 PM   #2
ssfrstlstnm
Member
 
Registered: Dec 2004
Location: IN, USA
Distribution: debian etch
Posts: 402

Rep: Reputation: 30
Try adding something like this to your .bashrc file:
Code:
export JAVA_HOME=/home/stephen/prog/jdk1.5.0_06
export PATH=$PATH:/home/stephen/prog/jdk1.5.0_06/bin
Of course you should change the path to match the location that you have installed java to. After that do this to load the new settings:
Code:
source /home/stephen/.bashrc
 
Old 02-10-2006, 10:36 PM   #3
Klogg
LQ Newbie
 
Registered: Feb 2006
Distribution: Fedora Core 5
Posts: 18

Original Poster
Rep: Reputation: 0
Actually, I already had that in my .bashrc file, and it didn't work. By the way, this is the error message that I get when trying to run a program that I made for a class:

Exception in thread "main" java.lang.NoClassDefFoundError: while resolving class: Tester
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 (/home/cole/Desktop/Project1/java.version=1.4.2)
at __libc_start_main (/lib/tls/libc-2.3.4.so)
at _Jv_RegisterClasses (/home/cole/Desktop/Project1/java.version=1.4.2)
Caused by: java.lang.ClassNotFoundException: java.lang.StringBuilder not found in [file:/usr/share/java/libgcj-3.4.4.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 02-11-2006, 01:18 PM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

1. Thanx for cutting/pasting the traceback - that's the single most valuable piece of
information to start troubleshooting:
Quote:
Exception in thread "main" java.lang.NoClassDefFoundError: while resolving class: Tester
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)
...
This says:
a) You've got "Java" in your $PATH (good!)
b) Java seems to have found it's basic runtime libraries (good!)
c) It's looking for something it's expecting *YOU* to provide: a public class named "Tester"

2. Your next step is to see if you can successfully compile and run *ANY* Java program.
Please try this:
a) Check your environment
Quote:
env|grep -i class
<= YOU'LL NOTICE THAT I DO *NOT* HAVE (OR NEED) AN EXPLICIT $CLASSPATH VARIABLE

env|grep -i java
JAVA_BINDIR=/usr/lib/jvm/jre/bin
JAVA_HOME=/usr/lib/jvm/jre
JAVA_ROOT=/usr/lib/jvm/jre
<= THIS IS JUST FYI - YOU PROBABLY DON'T EVEN NEED THIS

echo $PATH
/opt/mono/bin:/home/paulsm/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin:/usr/lib/jvm/jre/bin
<= THIS, TOO, IS JUST FYI
YOU PROBABLY *DON'T* NEED TO CHANGE *ANYTHING* IN YOUR USER ENVIRONMENT!
b) "cd" to any directory and write a simple "Hello world":
Quote:
cd /tmp
vi HelloJava.java
Code:
//
// Simple standalone test
//
public class HelloJava
{
  public static void main (String[] args)
  {
    System.out.println ("Hello from Java!\n");
  }
}
c) Compile it:
Quote:
javac HelloJava.java
d) Run it:
Quote:
java HelloJava
Hello from Java!
3. Capitalization is important: it needs to be "javac HelloJava.java", and "java HelloJava".

4. If you encounter ANY problems with either the compile or run commands, please cut-and-paste your EXACT commands and the EXACT error message back to LQ.

5. Otherwise, you should *probably* be able to figure out the difference between the above "HelloJava" and your "Tester".

Off the top of my head, I'm guessing that you probably *DO* have things capitalized correctly ... but maybe you're missing a "public" declaration. Or maybe you're using an "import" (which expects a separate "package" in a separate subdirectory).

Either way, we (the folks at LQ) would be happy to help!

Good luck .. PSM
 
Old 02-11-2006, 01:31 PM   #5
johnMG
Member
 
Registered: Jul 2003
Location: CT, USA
Distribution: Debian Sarge (server), Etch (work/home)
Posts: 601

Rep: Reputation: 32
Klogg, looks like you tried installing some GNU/Linux Java package, and then maybe bailed on that and tried installing Sun's? Is that right?

If so, remove one or the other, and try debugging your problem again.

If you want to use GNU's free Java, Fedora has great support.

If you want to use Sun's, you might consider installing it into the /opt directory (you can create it if it's not already there), to keep it separate from the rest of your system.
 
Old 02-11-2006, 02:13 PM   #6
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Klogg -

johnMG noticed that you installed Sun's JDK (perhaps in some local directory like "/home/stephen/prog/jdk1.5.0_06", preferably someplace like "/opt/jdk1.5.0_06"), yet your traceback shows you're actually using GNU Java ("/usr/lib/libgcj.so.5.0.0").

In my experience, you can usually get multiple different versions of Java to "play nice" with each other simply by adjusting your $PATH, $CLASSPATH and/or $JAVA_xxx variables. Having multiple different versions installed at the same time is often useful for testing, and often unavoidable if you have a package that wants to install it's "own" JVM (like, for example, Oracle or Websphere). It is NOT necessarily a problem.

Please focus on getting "Hello world" to work for now.

IMHO .. PSM
 
Old 02-11-2006, 03:06 PM   #7
Klogg
LQ Newbie
 
Registered: Feb 2006
Distribution: Fedora Core 5
Posts: 18

Original Poster
Rep: Reputation: 0
This is what I get when I type the stuff you told me to:

Quote:
[cole@dhcp80ffcae1 Project1]$ env|grep -i class
[cole@dhcp80ffcae1 Project1]$ env|grep -i java
JAVA_HOME=/opt/jdk1.5.0_06
[cole@dhcp80ffcae1 Project1]$ echo $PATH
/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/opt/jdk1.5.0_06/bin:/home/cole/bin:/opt/jdk1.5.0_06/bin
The Hello World program works fine. Oh, and by the way, I know there is nothing wrong with the Project1 program (the one with the Tester class), because it runs just fine in my university's Linux computer lab.

I did have another Java package installed before this one (although I had the same problems with that one). Both of them were from Sun's web site, though. The first one was just Java by itself, and the one I have now is from downloading the NetBeans/Java bundle. It's in the opt directory. I deleted the folder from my first install (which was in the usr directory, I think), although I'm not sure if that completely got rid of it. I'm just so confused and frustrated with how to install and uninstall stuff on Linux. I can't even get any media players installed right. But that's another problem...

Well, thanks for your help, guys. Hopefully we can get this figured out.
 
Old 02-11-2006, 03:30 PM   #8
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
OK, please do this:
1. Verify which version of Java you're actually picking up:
Quote:
java -version
java version "1.5.0_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing)
<= THE ODDS ARE VERY GOOD YOU *WON'T* BE PICKING UP THE SUN JDK 1.5.0, LIKE YOU SEE HERE
2. Create a custom environment script, and put it in your project directory.
When we're done, you may wish to put some or all of it in your .bashrc.
But for now, keep it simple and keep it in your project directory:
Quote:
vi env.rc
Code:
export PATH=/opt/jdk1.5.0_06/bin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/cole/bin:.
export JAVA_BINDIR=/opt/jdk1.5.0_06/bin
export JAVA_HOME=/opt/jdk1.5.0_06
export JAVA_ROOT=/opt/jdk1.5.0_06
<= NOTE THAT "/opt/java" COMES *FIRST* IN THIS PATH; *BEFORE* /USR/BIN...
3. Read your custom environment:[quote]
Quote:
. env.rc
4. Verify "java -version" now gives you the expected version.

5. Verify "Hello world" still works (a VERY important step!)

6. Try your class "Project1".

Whatever happens, *please* cut/paste your EXACT commands and the output for us to look at.

Thanx in advance .. PSM

Last edited by paulsm4; 02-11-2006 at 03:33 PM.
 
Old 02-11-2006, 05:04 PM   #9
Klogg
LQ Newbie
 
Registered: Feb 2006
Distribution: Fedora Core 5
Posts: 18

Original Poster
Rep: Reputation: 0
Hey! It works now! First it came up with this for the version:

Quote:
java version "1.4.2"
gcj (GCC) 3.4.4 20050721 (Red Hat 3.4.4-2)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
After I changed it, it came up with this:

Quote:
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)
I just tried putting the stuff in my .bashrc file, and now it works everywhere! Thanks a lot for the help. I appreciate it. I think my frustration level just went way down. So did this other version of Java get installed on my computer when I installed Linux or something? Because I'm pretty sure I didn't download that.
 
Old 02-11-2006, 05:21 PM   #10
johnMG
Member
 
Registered: Jul 2003
Location: CT, USA
Distribution: Debian Sarge (server), Etch (work/home)
Posts: 601

Rep: Reputation: 32
> So did this other version of Java get installed on my computer when
> I installed Linux or something? Because I'm pretty sure I didn't
> download that.

You don't have your profile filled in, so we can't tell what distro
you're using. For example, Fedora may install GNU's Java (GCJ) for
you when you do a fresh install and ask for Eclipse -- since they
got Eclipse running on GNU's Java.
 
Old 02-11-2006, 05:58 PM   #11
Klogg
LQ Newbie
 
Registered: Feb 2006
Distribution: Fedora Core 5
Posts: 18

Original Poster
Rep: Reputation: 0
Well, I'm running Red Hat Enterprise WS, so something like that probably happened. I guess I'll probably go ahead and fill in my profile, since it's very likely that I'll be using this forum again. You guys were very helpful. Thanks. I should have come here in the first place.
 
Old 02-11-2006, 07:05 PM   #12
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Another resource you might enjoy/find useful is Java Ranch:
http://www.javaranch.com

Just FYI - and again, congratulations on getting things working!
 
  


Reply



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
java won't work nibbler Fedora 4 09-08-2005 09:20 PM
getting java to work. meeep Ubuntu 1 08-21-2005 09:10 AM
Updated Java... now java apps dont work zidane2010 Linux - Software 6 05-04-2004 08:02 PM
Getting Java to work!!!! kkj Linux - Newbie 1 04-09-2004 01:59 AM
Getting Java To Work In Konqueror johnleemk Linux - Software 6 12-11-2003 04:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:05 AM.

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