LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-25-2004, 02:58 AM   #1
nro
Member
 
Registered: Oct 2003
Distribution: Mandrake 9
Posts: 46

Rep: Reputation: 15
Looking to run java commands outside bin/


I have a quick question that might just have a very simple solution.
I recently installed the Java 2 SDK in /usr/java/j2sdk1.4.2_05 and I'm running Mandrake 9.
All my compiling works as expected but I'm looking for an easier way to compile without having to run the command "cd /usr/java/j2sdk1.4.2_05/bin" everytime I open up a new Konsole.
Basically, I'm looking to run java commands such as "javac" and "java" from any location. For example:

mike@localhost mike]$ java
bash: java: command not found

Above is the result I get(my directory is /home/mike/).

If you have a solution to this problem or know somewhere to look, I would appreciate your help.

Thanks,
Mike
 
Old 08-25-2004, 03:04 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Code:
#!/bin/sh
export JAVA_HOME=/usr/lib/java
export MANPATH="$MANPATH:/usr/lib/java/man"
export PATH="$PATH:/usr/lib/java/bin:/usr/lib/java/jre/bin"
Replace the relevant bits with your actual path
to the sdk.

Throw that into your /etc/profile.d/ as j2sdk.sh
and chmod u+x it ...


Cheers,
Tink
 
Old 08-25-2004, 03:09 AM   #3
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 58
You should add the directory containing the java and javac exeutables to your $PATH environment variable. $PATH usually contains dirs such as /bin, /usr/bin, /usr/local/bin, /usr/X11R6/bin and so on - directories which the shell searches for executables.

Try typing PATH=$PATH:/usr/java/j2sdk1.4.2_05/bin and then type java -version from the shell prompt. Now you have added the directory to your $PATH, but only in the current shell (the open terminal - when you start another one it won't be there).

Open up your ~/.bashrc and add the line we typed above:
Code:
PATH=$PATH:/usr/java/j2sdk1.4.2_05/bin
In order to make sure ~/.bashrc is parsed everytime we start a new shell, be it a login shell or not, we need to add this to ~/.bash_profile:
Code:
if [ -f ~/.bashrc ]
then
    source ~/.bashrc
fi
The above snippet checks if ~/.bashrc exists and is a file. If it does exist it will be parsed. Now you should have access to java and javac no matter in what directory you are currently located.

You may also want to set the $JAVA_HOME and $CLASSPATH variables in a similar way. For more info on that check out the documentation on java.sun.com.


Håkan

Edit: I see Tink beat me to it. Oh well. Two different ways of doing the same thing don't hurt.

Last edited by hw-tph; 08-25-2004 at 03:10 AM.
 
Old 08-25-2004, 03:09 AM   #4
Electro
LQ Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
Add the path to java in your PATH environment variable. To do this type
PATH=$PATH:/usr/java/j2sdk1.4.2_05/bin

You can add the above to ~/.bashrc or ~/.bash_profile. If you want to make it global for all users. You can add in /etc/profile or /etc/bashrc.

Darn, someone beat me to it. Oh well. My way will also work.
 
Old 08-25-2004, 03:19 AM   #5
nro
Member
 
Registered: Oct 2003
Distribution: Mandrake 9
Posts: 46

Original Poster
Rep: Reputation: 15
Sorry, but you will have to bear with me here a little bit, I'm in my new stages of linux.
I don't follow along when you say "~/.bashrc or ~/.bash_profile" or "Replace your relevant bits with your actual path to the sdk". Where do I find these files/directories?
Unfortunately, I'm not to savvy yet on this stuff, so more basic instructions would be more than appreciated.

Thanks again,
Mike

Edit: I have tried Tink's method, didn't work for some reason...still get the same result.

Last edited by nro; 08-25-2004 at 03:21 AM.
 
Old 08-25-2004, 03:23 AM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Code:
#!/bin/sh
export JAVA_HOME=/usr/java/j2sdk1.4.2_05
export MANPATH="$MANPATH:$JAVA_HOME/man"
export PATH="$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin"
Try that one ...



Cheers,
Tink
 
Old 08-25-2004, 03:30 AM   #7
nro
Member
 
Registered: Oct 2003
Distribution: Mandrake 9
Posts: 46

Original Poster
Rep: Reputation: 15
Tink,
Still getting the same reply as before with the new file.

However, I am able to run the command after typing in the PATH command, but as expected, once I close the Konsole down and open it again, I am not able to.
 
Old 08-25-2004, 03:40 AM   #8
nro
Member
 
Registered: Oct 2003
Distribution: Mandrake 9
Posts: 46

Original Poster
Rep: Reputation: 15
Ahh, thank you for your help everyone. I figured out that '~' stood for, in my case, /home/mike/. Everything is in working condition exactly as I had hoped.

Thanks again,
Mike
 
  


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
/bin/... commands sources puishor Linux - General 2 06-23-2005 08:40 AM
adding commands to /bin (root user) xone Linux - Software 4 03-23-2004 01:26 PM
Java, I have downloaded the .bin file and run it ... now what ? TroelsSmit Linux - Newbie 3 03-02-2004 11:48 AM
2 Questions: java calling system commands? PERL vs Java? randomx Programming 28 11-28-2003 09:24 PM
shell problems ? cant run Java commands RedHat123 Linux - General 2 07-16-2002 11:29 PM


All times are GMT -5. The time now is 04:57 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration