LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How do I configure 'javac' and Using Java on Linux (https://www.linuxquestions.org/questions/linux-general-1/how-do-i-configure-javac-and-using-java-on-linux-289321/)

akosombo 02-12-2005 10:46 AM

How do I configure 'javac' and Using Java on Linux
 
I'm a Linux addict and a Java newbie. I just installed JDK/JRE 1.5.0. on Fedora Core 3 Now, how do I configure 'javac' and'java' on Fedora to compile a Java source code? Whenever I try to compile a source code, I get the following message:
"Exception in thread "main" java.lang.NoClassDefFoundError"
What do I need to do to make java(JVM) recognize and compile my source code?
Please, help me, sombody!!

XavierP 02-12-2005 11:31 AM

When you say you installed it, how did you go about doing this?

Welcome to LQ by the way :D

And moved: This thread is more suitable in Linux-General and has been moved accordingly to help your thread/question get the exposure it deserves.

craven 02-12-2005 03:49 PM

Usually this is a classpath problem. Verify all classpath settings are correct or use the -cp flag javac -cp <classpath>

IBall 02-13-2005 09:55 PM

Add
Code:

export CLASSPATH=/path/to/java/lib
to your ~/.bash_profile and then log out and back in again.

--Ian

linux_newbie_gu 02-13-2005 10:18 PM

ur right, iBall, but also u have to point to the java binary executables, java, javac, in the /usr/local/j2sdk.../bin inur bash_profile.

IBall 02-14-2005 01:11 AM

Quote:

Originally posted by linux_newbie_gu
ur right, iBall, but also u have to point to the java binary executables, java, javac, in the /usr/local/j2sdk.../bin inur bash_profile.
But that is not exactly difficult:
Code:

export JAVA_HOME=/usr/local/java
export PATH=$JAVA_HOME/bin:$PATH

--Ian

emo_kid_joe 03-12-2005 11:54 AM

I'm also having similar problems.

I'm a Linux newbie, so may have just done something stupid preventing it from working. I downloaded the blackdown sdk version 1.4.2 on recommedendation. I then chmod'd the file, unpacked it and ran the binary executable. It is installed in this way in /usr/local/java.

I then found a site recommending I edit PATH in my .bashrc file, another one telling me to change PATH in /etc/profile and here mentioning .bash_profile. Does it make any difference?

The relevant contents of these files are as follows:

.bashrc :
Code:

PATH="/usr/local/java/bin:."
export PATH


.bash_profile :
Code:

export JAVA_HOME=/usr/local/java
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=/usr/local/java/lib

(/etc/profile is unchanged).

Is something here causing a problem? I edited bashrc first, so I may have unwittingly overwritten something. This could also be true for .bash_profile.

As it stands, my bash shell does not recognise any commands beginnging with "java" at all, although "whereis java" gives the correct path. However, "whereis javac" etc. give no path.

Thanks for any help,

Joe

IBall 03-13-2005 08:26 AM

Quote:

Originally posted by emo_kid_joe
.bashrc :
Code:

PATH="/usr/local/java/bin:."
export PATH


.bash_profile :
Code:

export JAVA_HOME=/usr/local/java
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=/usr/local/java/lib

(/etc/profile is unchanged).


I would remove the line that sets your path in .bashrc. This will actually overwrite your existing path each time you open a new shell, so you will be able to run java and javac, but not ls, mv or anything else. When setting the PATH variable, ensure you add $PATH to the end, like this "export PATH=/new/dir:$PATH" so you still have your old path as well as your addition.

I always add things to .bash_profile, but that is more of a personal choice than anything fixed. .bash_profile is read on login, and .bashrc is read each time your open a new shell or xterm. This means that if you add the "export PATH ..." line to .bashrc, the path will keep growing and growing, so eventually it will be "/usr/local/java/bin:/usr/local/java/bin:/usr/local/java/bin:/usr/local/java/bin:/usr/local/java/bin:/bin:/usr/bin:." which you don't want.

.bash_profile and .bashrc each have their own uses, but both are bash configuration files for the individual user. /etc/profile is a global bash config file, so if you want java to be available to ALL users on your system then add the export lines above to /etc/profile. Otherwise, add to .bash_profile.

Sorry if this is a touch long winded
--Ian


All times are GMT -5. The time now is 10:29 AM.