File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to set classpath for java in Linux Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to set classpath for java in Linux" Watch "How to set classpath for java in Linux" New topic
Author

How to set classpath for java in Linux

Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 157
Can anyone say me how to set classpath for java in Linux.
Like in windows, we will go to my computer --> properties(right click) ---> adavnced tab --> Environment variable and setting the classpath.

In Linux how we will be setting?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10329
    
    8

http://faq.javaranch.com/java/HowToSetTheClasspath
Scroll down for the Linux version


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Neeba Rebbaca
Ranch Hand

Joined: Oct 21, 2008
Posts: 157
Before that how can i set path for java?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10329
    
    8

A simple google would have given you something like http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14139
    
  18

Which Linux distribution are you using? Different Linux distro's have different preferred ways for installing Java. Google for "<your distro name> Java".

On Ubuntu, the best way to install Sun JDK 6, which will automatically set up your path correctly, is entering the command:
sudo apt-get install sun-java6-jdk


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Samir Kureshi
Greenhorn

Joined: Mar 21, 2009
Posts: 19
try like this....
export CLASSPATH=/local/home/soft/bea81sp6/jdk142_11


hope would help

Thanks,
Samir
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38729
    
  23
Samir Kureshi wrote:try like this....
export CLASSPATH=/local/home/soft/bea81sp6/jdk142_11
No, that won't help at all. That sets a CLASSPATH to a value which is unnecessary and will lose you access to your local files. It is also specific you your computer, and appears to have some errors, eg missing out .s.

You should never set a permanent CLASSPATH if you can possibly help it. You should use the -cp flags on the "java" and "javac" tools, or put it in the manifest file. For the java and javac tools, look here, then look at the links on the right.
Pouya Arvandian
Greenhorn

Joined: Oct 15, 2009
Posts: 1
If you're using Ubuntu:

open terminal: gedit .bashrc

then append the following to the bottom of the file:

export JAVA_HOME=/<path to jdk>
export PATH=$JAVA_HOME/bin:$PATH


this worked perfectly for me after I downloaded and compiled jdk binaries from sun website. Hope it helps you too.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38729
    
  23
Welcome to JavaRanch

There is a better way to install Java on a Debian-based Linux installation, which includes Ubuntu: Jesper Young told us here to use sudo apt-get install sun-java6-jdk which sets the PATH automatically. There is a similar instruction to update it.
An rpm-based Linux installation (eg Suse, Fedora) can use a similar instruction with the rpm tool.

The instructions to use export PATH in the .bashrc file should work for any "bash" terminal; Ubuntu and OpenSUSE and Fedora usually use "bash". You can probably find out which terminal you are using by giving a nonsense instruction to the terminal
campbell@linux-747u:~> which bash
/bin/bash
campbell@linux-747u:~> oeirhglkcjxnvgiud
bash: oeirhglkcjxnvgiud: command not found
campbell@linux-747u:~>
And the name of the shell program appears as part of the error message
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to set classpath for java in Linux