Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've done java development before but generally on windows (but I'm by no means an expert).

I just want to set my CLASSPATH. When I run:

echo $CLASSPATH

(Is that right)? I get a empty line. So, it appears to me that my computer does not have a "Classpath" setup. What is the best practice to setup the classpath in Ubuntu (and linux in general)?

I'm using the default java for Ubuntu which should be OpenJDK. Not sure it's important, but I want to use Rhino (http://en.wikipedia.org/wiki/Rhino_(JavaScript_engine)) Note: I've been able to install Rhino via the package manager. There is both documentation and rhnio packages. Then, the commands are js and rhino-debugger

share|improve this question

2 Answers 2

up vote 1 down vote accepted

I'm not a Java programmer, so I don't know the correct value for CLASSPATH. But, you seem to. You can add it to ~/.bashrc like so:

CLASSPATH=/path/to/1:/path/to/2:/etc

The change will take effect globally the next time you log in. However, it will take effect immediately in new shells.

Additionally, if you want to set it for just one particular command, do this:

CLASSPATH=/something command-here arg1 arg2

A third way would be to create a wrapper script, which would be appropriate if you needed to set multiple variables or if you needed to determine appropriate values programmatically:

#!/bin/bash
export CLASSPATH=/something
export ANOTHER_ENV_Variable=foo

exec your_fancy_program "$@"
share|improve this answer
    
You are right, this would work but I guess what I'm after is what is the standard way to set the classpath. I think, in fact, there are several ways to set environment variables in Linux. This is probably the "problem" I face. What I seek is the "standard" way to do this, de facto or otherwise... –  Frank V Dec 22 '11 at 22:43
    
@FrankV: See my edit above. There's no such thing as a single "standard" way to set environment variables in Linux. I've posted the three most common ways. You should choose the method that makes the most sense for your situation. A single "standard" would be too limiting and not useful. –  Scott Severance Dec 23 '11 at 8:53
2  
To set the classpath, you can also use the -cp option, e.g. java -cp /path/to/class/path name –  Lekensteyn Dec 23 '11 at 11:09
    
+1 on not using env vars, but rather using the command-line options. For more context, see my answer here on the same subject: askubuntu.com/questions/186693/… –  michael_n Sep 29 '12 at 8:25

that's what happened with me.. i left empty spaces while typing.. it fixed when i removed spaces.

1) if you want to set classpath permanently then 1) find out where java is installed.. you may use " whereis java " openjdk-7/6 is in /usr/lib/jvm/.....

2) we need to set up CLASSPATH in /etc/environment

  sudo gedit /etc/environment

3) add the following likes .. ( DONT LEAVE ANY SPACES WHILE TYPING)(customize according to your java version and installation) (this home path is for open jdk 7)

  JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386/bin"

   export JAVA_HOME

   CLASSPATH=".:/usr/lib/jvm/java-7-openjdk-i386/lib:/home/laptop/Desktop/a2"

    export CLASSPATH

separate directory by ":"

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.