LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 09-22-2006, 08:31 PM   #1
une
Member
 
Registered: May 2004
Location: Australia
Distribution: Mandrake 10, Puppy Linux 2.13
Posts: 201

Rep: Reputation: 30
My system can't find Java tools


I installed Java SDK 1.4.2_07 a year or so ago on my Linux system in;
/usr/java/j2sdk1.4.2_07/
I also carried out some procedures at this time to make the Java tools accessable from any directory. Exactly what these procedures were I cannot recall.
It all worked fine. I could execute Java commands from any directory.

Recently I connected a router to provide ADSL connectivity to the Internet.
When I did this I noticed that my command prompt changed from;
[username@localhost username]$
to
[username@myISPsName username]$

As soon as I did this I found I could no longer get Java commands to work from anywhere.
All I get is error messages such as;
bash: java: command not found

What has happened? Has my environment variable been changed somehow?
How do I get Java commands working again?

Even when I change directory to
/usr/java/j2sdk1.4.2_07/bin/
and then enter
[username@myISPsName bin] java -version
I get the error message;
bash: java: command not found

I am quite confused.
 
Old 09-23-2006, 01:19 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Do an "echo $PATH" to see if /usr/java/j2sdk1.4.2_07 is listed. Presumably it isn't and you'll need to add it. It's not working even when you cd to /usr/java/j2sdk1.4.2_07 and run "java -version", because the current directory (i.e. .) isn't in your $PATH. For that reason, you'd need to do "./java -version" from within that directory.
 
Old 09-23-2006, 03:34 AM   #3
une
Member
 
Registered: May 2004
Location: Australia
Distribution: Mandrake 10, Puppy Linux 2.13
Posts: 201

Original Poster
Rep: Reputation: 30
Here is the result;
[username@myISP username]$ echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/share/pvm3/


What file do I edit to add the Java path?

As I mentioned this problem appeared when I added the router, which changed the hostname at the command prompt. Why this happened eludes me.

I recall that I when I first installed Java SDK, I did add something to ensure Java commands could be executed from anywhere, I have realized that in
/etc/profile.d/
there is a file named
java.sh
the contents of this file are as follows
export PATH=$PATH:/usr/java/j2sdk1.4.2_07/bin/

Should this not have added the path as required automatically?

I think java.sh is a script that could be executed, so I did the following
[username@myISP profile.d]$ java.sh
bash: java.sh: command not found

I thought this comand would cause the script to execute.
 
Old 09-23-2006, 12:26 PM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
If you have a .bashrc or .bash_profile in your home directory, then you can add the line "export PATH=$PATH:/usr/java/j2sdk1.4.2_07/bin/" there. Obviously, if there's already an "export PATH=..." line present, then you just need to add the directory (i.e. /usr/java/j2sdk1.4.2_07/bin" to the end.

Quote:
Originally Posted by une
Should this not have added the path as required automatically?
Yes, if the script was being executed. However, I don't have a clue as to what it's being called from (i.e. what other script is supposed to call it), or not as the case seems to be.

Quote:
Originally Posted by une
I think java.sh is a script that could be executed, so I did the following
[username@myISP profile.d]$ java.sh
bash: java.sh: command not found

I thought this comand would cause the script to execute.
Yes, the script would be executed if you had the current directory in your $PATH. Since it isn't in your $PATH, you need to use ./java.sh. Of course, the script would need execute permissions set for you to be able to run it.
 
Old 09-23-2006, 12:45 PM   #5
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
I decided to put this bit in a separate post, since I didn't want to edit the previous one entirely.

Actually, you probably don't need to add the "export PATH=..." line to your .bashrc or .bash_profile. I have found out that the scripts in /etc/profile.d are executed when you log in, so the problem must be with your java.sh. Try adding the following line to the top of the script:

#!/bin/bash

Also, check that executable permissions are set on the file. Run "ls -l" to find out. If you don't see a single x in that output, then the executable permissions need to be set. Do this with "chmod a+x java.sh".
 
Old 09-24-2006, 12:30 AM   #6
une
Member
 
Registered: May 2004
Location: Australia
Distribution: Mandrake 10, Puppy Linux 2.13
Posts: 201

Original Poster
Rep: Reputation: 30
The permissions are as follows and OK I believe;
[root@myISP profile.d]# ls -l java.sh
-rwxr-xr-x 1 root root 46 Sep 24 15:22 java.sh*
[username@myISP profile.d]$ ls -l java.sh
-rwxr-xr-x 1 root root 46 Sep 24 15:22 java.sh*

I executed chmod a+x java.sh as root just to be sure.

I tried adding the line
#!/bin/bash
to java.sh, then logging out and logging back in again.
I still had the same problem. No Java commands worked. I then removed this extra line.

I then manually executed the contents of java.sh as root by executing the line of code contained in it from the command prompt as follows;.
[root@myISP username] export PATH=$PATH:/usr/java/j2sdk1.4.2_07/bin/
Then root could access Java commands OK, but only if I stay in the directory from where I executed the export command.
I then manually executed the contents of java.sh as username using the same method.
Then username could access Java commands OK, but only if I stay in the directory from where I executed the export command.
It seems every time I change directory I have to execute the export command again for that directory.

Is the execution of the java.sh script at login not working properly? Could this be asscociated with the change in host from localhost to myISP when I connected the router? This is after all the event that seemed to trigger this entire problem.

How do I get back to the situation where all users could execute all Java commands from any directory?

Last edited by une; 09-24-2006 at 09:42 PM.
 
Old 09-29-2006, 01:42 PM   #7
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
That's very odd. I don't see why connecting your machine to a router would affect these things :/. As for letting all users execute commands, well, you could add that directory to the PATH line in /etc/profile, but I'm not sure if this is the best thing to do.
 
Old 09-30-2006, 04:02 AM   #8
une
Member
 
Registered: May 2004
Location: Australia
Distribution: Mandrake 10, Puppy Linux 2.13
Posts: 201

Original Poster
Rep: Reputation: 30
I suppose coincidences do occur so I cannot be certain that addition of the modem/router caused the problem.
I posted the problem and some relevant files to a Linux User Group as follows;

# HERE IS MY ORIGINAL .bash_profile
#########################################
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME
#########################################

#########################################
# I THEN EDITED .bash_profile AS FOLLOWS, LOGGED OUT & IN;
#
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME
export PATH=$PATH:/usr/java/j2sdk1.4.2_07/bin/

## THIS DID NOT WORK. JAVA COMMANDS NOT FOUND.
##################################################

##################################################

## SO I EDITED IT AS FOLLOWS, LOGGED OUT & IN;

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH=$PATH:/usr/java/j2sdk1.4.2_07/bin/
unset USERNAME

## THIS DID NOT WORK. JAVA COMMANDS NOT FOUND.
#################################################

################################################
## I THEN EDITED IT AS FOLLOWS, LOGGED OUT & IN;
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/java/j2sdk1.4.2_07/bin/

export PATH
unset USERNAME
## THIS DID NOT WORK EITHER. JAVA COMMANDS NOT FOUND.
#########################################################

#########################################################
Below are my original files;
/home/<user>/.bash_profile
/home/<user>/.bashrc
/etc/bashrc
/etc/profile

Can you see anywhere where the PATH is being reset in any of these?
I am not quite sure how to interpret the contents of these files.
Can you think of any other edits that may work?
#########################################################
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME
########################################################

#########################################################
# .bashrc

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
#######################################################


#########################################################
# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# by default, we want this to get set.
# Even for non-interactive, non-login shells.
if [ "`id -gn`" = "`id -un`" -a `id -u` -gt 99 ]; then
umask 002
else
umask 022
fi

# are we an interactive shell?
if [ "$PS1" ]; then
case $TERM in
xterm*)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
;;
*)
;;
esac
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "

if [ -z "$loginsh" ]; then # We're not a login shell
for i in /etc/profile.d/*.sh; do
if [ -x $i ]; then
. $i
fi
done
fi
fi

unset loginsh
# PVM environement
export PVM_RSH=/usr/bin/rsh
export PVM_ROOT=/usr/share/pvm3
export PVMD_NOHOLD=ON
export PVM_TMP=/var/run/pvm3
export XPVM_ROOT=/usr/X11R6/lib/xpvm/
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/share/pvm3/
##########################################################

#########################################################

# /etc/profile -*- Mode: shell-script -*-
# (c) MandrakeSoft, Chmouel Boudjnah <chmouel@mandrakesoft.com>

loginsh=1

# Users generally won't see annoyng core files
[ "$UID" = "0" ] && ulimit -S -c 1000000 > /dev/null 2>&1

if ! echo ${PATH} |grep -q /usr/X11R6/bin ; then
PATH="$PATH:/usr/X11R6/bin"
fi

if [ "$UID" -ge 500 ] && ! echo ${PATH} |grep -q /usr/games ; then
export PATH=$PATH:/usr/games
fi

umask 022

USER=`id -un`
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
HISTCONTROL=ignoredups
HOSTNAME=`/bin/hostname`
HISTSIZE=1000

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

# some old programs still use it (eg: "man"), and it is also
# required for level1 compliance for LI18NUX2000
NLSPATH=/usr/share/locale/%l/%N

export PATH PS1 USER LOGNAME MAIL HOSTNAME INPUTRC NLSPATH
export HISTCONTROL HISTSIZE

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

unset i
#########################################################
#########################################################
############################################END_OF_MY_POST



A person responded to the above with a suggestion as follows;
G'day UNE,
Yeah, I think I can probably see it.
In your /etc/bashrc you have a line near the bottom:

"PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/share/pvm3/".

If I'm right, thats your prob.

Change to
PATH=$PATH:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/share/pvm3/

In my previous response I was going to mention that if PATH was being
clobbered, the culprit might be identifiable from your existing PATH
ie the pvm3.

It seems to bear this out.

And don't forget to clobber the person that put that line in

Cheers,
A Helper.

###I am away from home now so I will try the suggestion when I return and post results.##
 
Old 10-01-2006, 06:49 AM   #9
une
Member
 
Registered: May 2004
Location: Australia
Distribution: Mandrake 10, Puppy Linux 2.13
Posts: 201

Original Poster
Rep: Reputation: 30
The problem was solved as follows;
in /etc/bashrc I changed the last line from;
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/share/pvm3/

TO

export PATH=$PATH:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/share/pvm3/

Why it worked I do not know. Any ideas?
Thanks to Daniel from the SLUG (Sydney Linux Users Group).
He saved my bacon.
 
Old 10-01-2006, 07:01 AM   #10
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Glad you got it fixed.

export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/share/pvm3/

sets $PATH to contain only those directories listed there. When you use

export PATH=$PATH:/other/directories,

it assigns $PATH to its original value, plus those other directories.
 
Old 10-03-2006, 03:46 AM   #11
une
Member
 
Registered: May 2004
Location: Australia
Distribution: Mandrake 10, Puppy Linux 2.13
Posts: 201

Original Poster
Rep: Reputation: 30
What is the language called that all these scripts are written in?
 
Old 10-03-2006, 11:59 AM   #12
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Hmm, I was going to say Bash, but I don't know if that's technically what you say. It's probably safer to say that they're Bash scripts. Obviously if you were using a different shell, then the files would be written in whatever syntax is used in that shell.
 
  


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
Where can I find tools to open and work on harddrives? abefroman General 64 08-20-2005 05:12 AM
Where can i find the Antivirus tools for linux? tonewangl Linux - Software 5 06-12-2005 03:02 AM
how do I set a path for my java command line tools darkone66669 Linux - Newbie 1 04-19-2004 06:28 PM
2 Questions: java calling system commands? PERL vs Java? randomx Programming 28 11-28-2003 08:24 PM
System tools ust Linux - Software 2 11-05-2003 09:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 03:16 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