4

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.

4
  • What is the output of java -version? Can you also run update-java-alternatives -l and post the output Can you include the error messages that you get? Commented May 18, 2010 at 3:23
  • What happens when you run java, not javac? Commented May 18, 2010 at 3:25
  • I don't have a compiled class to run java on ... The Test.java file is just some simple code. Just throws errors as expected. Commented May 18, 2010 at 3:29
  • I guess spong was right and that somehow the environment variables needed to be exported for javac to see them. Commented May 18, 2010 at 3:32

2 Answers 2

7

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.
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you spong for the much needed lesson in bash variable scoping!
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.
@blacksensei Use the -cp or -classpath option with the java or javac commands.
0

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......

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.