views:

394

answers:

2

First off I'm running Ubuntu 9.10

I've edited the /etc/environment file to look like this:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
JAVA_HOME="/usr/lib/jvm/java-6-sun-1.6.0.20"
CLASSPATH="/home/travis/freetts/lib/freetts.jar:/home/travis/freetts/lib/jsapi.jar:."

I then run "source /etc/environment" to make sure the changes are included. Then I try compiling my simple test program using this:

javac Test.java

It throws out a few errors, but when I compile like this:

javac -cp /home/travis/freetts/lib/freetts.jar:/home/travis/freetts/lib/jsapi.jar:. Test.java

It works just fine, this leads me to believe that for some reason javac isn't seeing the CLASSPATH environment variable? I can echo it and everything in the terminal:

echo $CLASSPATH gives me what I put in.

Any help on this would be greatly appreciated.

+3  A: 

Does it work if you put export in /etc/environment?

export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
export JAVA_HOME="/usr/lib/jvm/java-6-sun-1.6.0.20"
export CLASSPATH="/home/travis/freetts/lib/freetts.jar:/home/travis/freetts/lib/jsapi.jar:."

I'm guessing that CLASSPATH isn't set before you source the script, and so you are only setting a local variable.


Here's an illustration of what might be happening:

superman@metro:~$ Z=foo        # Only sets for this shell
superman@metro:~$ echo $Z
foo
superman@metro:~$ /bin/bash
superman@metro:~$ echo $Z      # Not set in sub-processes

superman@metro:~$ exit
exit
superman@metro:~$ export Z     # When exported, is part of environment
superman@metro:~$ /bin/bash
superman@metro:~$ echo $Z      # And now visible to sub-processes
foo
superman@metro:~$ exit
exit
superman@metro:~$ help export
export: export [-nf] [name[=value] ...] or export -p
     NAMEs are marked for automatic export to the environment of
    subsequently executed commands.  If the -f option is given,
    the NAMEs refer to functions.  If no NAMEs are given, or if '-p'
    is given, a list of all names that are exported in this shell is
    printed.  An argument of '-n' says to remove the export property
    from subsequent NAMEs.  An argument of '--' disables further option
    processing.
spong
Thank you spong for the much needed lesson in bash variable scoping!
Travis
Setting a system-wide `CLASSPATH` is not a good idea - those JARs will then be included for any Java application that you run on your system.
Jesper
A: 

Did u export all the environment variables in profile file? i didn't see any export command in the file specified by u......use export and try once......

kumarasvn