LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Mandriva
User Name
Password
Mandriva This Forum is for the discussion of Mandriva (Mandrake) Linux.

Notices


Reply
  Search this Thread
Old 03-31-2006, 10:22 AM   #1
ohade
LQ Newbie
 
Registered: Jul 2005
Posts: 23

Rep: Reputation: 15
problems with java


Hi all,

I have 2 problems:
1) If I want to compile a file.java I must go to the directory where java had been installed. (can't just write java on shell)
2) After I compiled the java file I can't run it unless
I copy the file to the directory where java had been installed and write ./java HelloWorld ( and not ./java HelloWorld.class).

How can i fixed those problems?

Tnx.
 
Old 03-31-2006, 11:33 AM   #2
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,461
Blog Entries: 1

Rep: Reputation: 66
In Unix/Linux there is a environmental variable that specify where to search for a given command in CLI. It is PATH.
Code:
[miguel@sulfer ~]$ which javac
/usr/bin/which: no javac in (/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/miguel/bin)
[miguel@sulfer ~]$ javac
-bash: javac: command not found
[miguel@sulfer ~]$ echo $PATH
/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/miguel/bin
[miguel@sulfer ~]$ ls /usr/java/jdk1.5.0_06/bin/javac
/usr/java/jdk1.5.0_06/bin/javac
[miguel@sulfer ~]$ export PATH=${PATH}:/usr/java/jdk1.5.0_06/bin
[miguel@sulfer ~]$ which javac
/usr/java/jdk1.5.0_06/bin/javac
[miguel@sulfer ~]$
You need to set the PATH variable with the path of your java bin directory, just like I did above.
 
Old 03-31-2006, 11:37 AM   #3
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,461
Blog Entries: 1

Rep: Reputation: 66
I am not a java expert, but to run a java program, I think you need to setup a JAVA_HOME variable that points to the root dir of your java installation. In the previous example it is /usr/java/jdk1.5.0_06.
Code:
$ export JAVA_HOME=/usr/java/jdk1.5.0_06
 
Old 03-31-2006, 12:43 PM   #4
ohade
LQ Newbie
 
Registered: Jul 2005
Posts: 23

Original Poster
Rep: Reputation: 15
About the first reply,

After I close and reopen the shell it didn't remember those commands.
How can I save those commands?
 
Old 03-31-2006, 12:50 PM   #5
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,461
Blog Entries: 1

Rep: Reputation: 66
put it in your .bashrc file.
 
Old 03-31-2006, 04:10 PM   #6
bobbelfield
Member
 
Registered: Jan 2006
Location: Australia
Distribution: Mandriva 2006
Posts: 154

Rep: Reputation: 30
also there is no need to enter ".class" after the file name .That is the default parameter
The file to put JAVA_HOME in is bash_profile


# .bash_profile

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

# User specific environment and startup programs
JAVA_HOME=/usr/java/j2sdk1.4.1_03/bin/
PATH=$PATH:$HOME/bin:/usr/java/j2sdk1.4.1_03/bin/

export PATH JAVA_HOME
unset USERNAME
 
  


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
Problems with Java Web Start (java 1.4.2 - 1.5.0) on Slackware Egy Slackware 11 05-10-2005 07:30 AM
JAVA:(jwstric2) Problems in JAVA-LINUX nedian123 Programming 1 06-28-2004 05:12 PM
Java problems atheist Debian 3 02-14-2004 12:03 AM
anyone having problems like this with java deepsix Linux - Software 2 08-28-2003 10:35 AM
Java Problems crash89 Linux - General 0 08-03-2001 07:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Mandriva

All times are GMT -5. The time now is 06:59 PM.

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