wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Installin Java on Linux 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 » Java » Beginning Java
Bookmark "Installin Java on Linux" Watch "Installin Java on Linux" New topic
Author

Installin Java on Linux

Daurice Jordan
Greenhorn

Joined: Feb 01, 2005
Posts: 7
I am sure this topic has been covered before but I want to post something new because I have tried everything that I have seen on the web and I am still having problems. The history of my problem goes as follows:

I have Fedora 2 installed on my machine.

Logged in as root I installed j2sdk1.4.2_07 from java.sun.com.
/usr/local/j2sdk1.4.2_07 is the install directory

copy the self-extracting bin file over, made it executable and ran it

The install went ok, however when i went to use /usr/local/j2sdk1.4.2_07/bin/javac it was not working. I kept getting "command not found." Even though I was attempting to run the actual file. I did not think environment varibles mattered.

I researched "activating javac" and found info on how to install the pluggin for netscape/mozilla. I was able to do that successfully but still javac was NOT working

I added /usr/local/j2sdk1.4.2_07 to my PATH and javac worked??? I don't understand why it did not work before.

I wrote a small hello world program and I am getting exeption in thread "main" java.lang.noClassDefFoundError. The program compiles okay but when I run it I get that error.

I attemped to set up the
CLASSPATH to /usr/local/j2sdk1.4.2_07/lib/tools.jar:/usr/local/j2sdk1.4.2_07/jre/lib/rt.jar and
JAVA_HOME to /usr/local/j2sdk1.4.2_07 and still I get the same error.

PATH, CLASSPATH and JAVA_HOME are set in the /etc/profile

As far as I know everything is set up properly. Please help!
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
All I know is that the bin directory does need to be in your path. The following is from my /etc/profile file on Red Hat Linux:


export JAVA_HOME=/usr/java/j2sdk1.4.2_06
export PATH=$PATH:$JAVA_HOME/bin
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
this will probably end up moved to the Linux/Unix forum before too long, but...

could you do a "ls -l" on your /usr/local/j2sdk1.4.2_07/bin directory and copy&paste the results here, to see if "java" and "javac" are present and have the correct permissions? if you also cut&pasted your environment variables, that might help too. (that should be the "set" command in bash, but i'm not at a linux box ATM so i can't verify that.)
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Don't set your CLASSPATH to include the .jar files included with the JDK. They are picked up automatically. Instructions for setting the CLASSPATH are in the FAQ.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Daurice Jordan
Greenhorn

Joined: Feb 01, 2005
Posts: 7
[root@localhost bin]# ls -l
total 1732
-rwxrwxr-x 1 root root 66420 Jan 15 14:08 appletviewer
-rwxrwxr-x 1 root root 66156 Jan 15 14:12 extcheck
-rwxr-xr-x 1 root root 1080 Jan 15 14:22 HtmlConverter
-rwxrwxr-x 1 root root 66188 Jan 15 13:58 idlj
-rwxrwxr-x 1 root root 66156 Jan 15 14:00 jar
-rwxrwxr-x 1 root root 66156 Jan 15 14:00 jarsigner
-rwxrwxr-x 1 root root 64940 Jan 15 13:52 java
-rwxrwxr-x 1 root root 66156 Jan 15 13:53 javac
-rwxrwxr-x 1 root root 66156 Jan 15 13:53 javadoc
-rwxrwxr-x 1 root root 66156 Jan 15 13:54 javah
-rwxrwxr-x 1 root root 66156 Jan 15 14:09 javap
-r-xr-xr-x 1 root root 1789 Jan 15 14:09 java-rmi.cgi
-rwxrwxr-x 1 root root 66156 Jan 15 14:12 jdb
-rwxrwxr-x 1 root root 66156 Jan 15 13:59 keytool
-rwxrwxr-x 1 root root 66188 Jan 15 14:00 kinit
-rwxrwxr-x 1 root root 66188 Jan 15 14:00 klist
-rwxrwxr-x 1 root root 66188 Jan 15 14:00 ktab
-rwxrwxr-x 1 root root 66156 Jan 15 14:10 native2ascii
-rwxrwxr-x 1 root root 66380 Jan 15 14:11 orbd
-rwxrwxr-x 1 root root 66420 Jan 15 14:00 policytool
-rwxrwxr-x 1 root root 66156 Jan 15 14:09 rmic
-rwxrwxr-x 1 root root 66156 Jan 15 14:09 rmid
-rwxrwxr-x 1 root root 66156 Jan 15 14:09 rmiregistry
-rwxrwxr-x 1 root root 66156 Jan 15 14:10 serialver
-rwxrwxr-x 1 root root 66188 Jan 15 14:11 servertool
-rwxrwxr-x 1 root root 66188 Jan 15 14:11 tnameserv

env varibles:

SSH_AGENT_PID=951
HOSTNAME=localhost.localdomain
SHELL=/bin/bash
TERM=xterm
HISTSIZE=1000
GTK_RC_FILES=/etc/gtk/gtkrc:/root/.gtkrc-1.2-gnome2
WINDOWID=33563500
OLDPWD=/usr/local/j2sdk1.4.2_07
USER=root
LS_COLORS=no=00:fi=00 i=00;34:ln=00;36 :p i=40;33:so=00;35:bd=40;33;01:cd=40;33;01 r=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:
*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:
*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=00;31:
*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:
*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:
*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35:*.bmp=00;35:*.xbm=00;35:
*.xpm=00;35:*.png=00;35:*.tif=00;35:
GNOME_KEYRING_SOCKET=/tmp/keyring-ImFqwh/socket
SSH_AUTH_SOCK=/tmp/ssh-pRcJF892/agent.892
SESSION_MANAGER=local/localhost.localdomain:/tmp/.ICE-unix/892
USERNAME=root
MAIL=/var/spool/mail/root
DESKTOP_SESSION=default
PATH=/usr/local/j2sdk1.4.2_07/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:
/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
INPUTRC=/etc/inputrc
PWD=/usr/local/j2sdk1.4.2_07/bin
JAVA_HOME=/usr/local/j2sdk1.4.2_07
LANG=en_US.UTF-8
GDMSESSION=default
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
HOME=/root
SHLVL=2
GNOME_DESKTOP_SESSION_ID=Default
BASH_ENV=/root/.bashrc
LOGNAME=root
CLASSPATH=/usr/local/j2sdk1.4.2_07/lib/tools.jar:/usr/local/j2sdk1.4.2_07/jre/lib/rt.jar
LESSOPEN=|/usr/bin/lesspipe.sh %s
DISPLAY=:0.0
G_BROKEN_FILENAMES=1
COLORTERM=gnome-terminal
XAUTHORITY=/root/.Xauthority
_=/bin/env


/etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^| $1($| " ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
fi
}

# Path manipulation
if [ `id -u` = 0 ]; then
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
pathmunge /usr/local/j2sdk1.4.2_07/bin
fi

pathmunge /usr/X11R6/bin after

unset pathmunge

# No core files by default
ulimit -S -c 0 > /dev/null 2>&1

USER="`id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"

HOSTNAME=`/bin/hostname`
HISTSIZE=1000

JAVA_HOME=/usr/local/j2sdk1.4.2_07
CLASSPATH=/usr/local/j2sdk1.4.2_07/lib/tools.jar:/usr/local/j2sdk1.4.2_07/jre/lib/rt.jar

if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
INPUTRC=/etc/inputrc
fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC JAVA_HOME CLASSPATH

for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
. $i
fi
done

unset i

(Marilyn cut long lines)
[ February 01, 2005: Message edited by: Marilyn de Queiroz ]
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
the only thing i can see that's clearly wrong is that the CLASSPATH shouldn't have to be set. it definitely shouldn't include those two JARs. i'm not even sure if you need JAVA_HOME set, but perhaps you do.

edit: or do you mean the "java" binary won't run your own compiled java programs? if so, try setting CLASSPATH to either be just ".", or else to at least include "." as one of its directories. then cd to wherever you keep your class files and try to run them from there.
[ February 01, 2005: Message edited by: M Beck ]
Daurice Jordan
Greenhorn

Joined: Feb 01, 2005
Posts: 7
I tried NOT setting the classpath and I get the same error.

Also here is my program:

//This is a Java test.

public class Test
{
public static void main(String args[])
{
System.out.println( "Welcome to Java Programming!");
}
}


This is my output:

[root@localhost java]# javac Test.java <<compiles okay
[root@localhost java]# ll
total 8
-rw-r--r-- 1 root root 430 Feb 1 11:36 Test.class
-rw-r--r-- 1 root root 147 Feb 1 00:45 Test.java
[root@localhost java]# java Test.class
Exception in thread "main" java.lang.NoClassDefFoundError: Test/class
[root@localhost java]#
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
you have a command-line problem. you shouldn't be saying "java Test.class", but simply "java Test"; the JVM will add on the ".class" for you.

yeah, that bit is really confusing. it had me tearing my hair out for fifteen minutes, myself, when i got started.
Daurice Jordan
Greenhorn

Joined: Feb 01, 2005
Posts: 7
AHHHHH! DON'T I FEEL LIKE A FREAKIN HEEL. Thanks M Beck as well as the others. It works now!
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by M Beck:
you have a command-line problem. you shouldn't be saying "java Test.class", but simply "java Test"; the JVM will add on the ".class" for you.

yeah, that bit is really confusing. it had me tearing my hair out for fifteen minutes, myself, when i got started.


This happens because Java uses "." to separate packages in a package heirarchy. Typically packages correspond to directories in the file system, so the JVM often turns "." into "/" (or the appropriate directory system for your OS). You can see this in the "ClassNotFound" error message. Notice that it says that it can't find "Test/class".

Layne


Java API Documentation
The Java Tutorial
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Installin Java on Linux
 
Similar Threads
classnotfound Java->mysql jdbc problem!
java installation problem in linux
Something is wrong with my Java on LInux...
Problems with Java Home in VMBox
NoClassDefFound error