Java doesn´t find the CLASSPATH (System variable)

  1. The problem statement, all variables and given/known data:

As a excercise I have to compile a program (Hello2.java) with a class file (HelloText.java) in another directory. (As you seen in the screenshot)
I�m setting a PATH and a CLASSPATH (system variables). It�s working without a command. But if I use a command like java or javac which I need to compile ITS NOT WORKING.
I can�t retrace why the bash is doing this respectively is not doing this.

  1. Relevant commands, code, scripts, algorithms:

PATH=$PATH:<directory>, CLASSPATH =$CLASSPATH:<directory>, cd (change directory), javac

  1. The attempts at a solution (include all code and scripts):

see the screenshot.

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Beuth Hochschule f�r Technik, Berlin, Germany, Radners, Programmierung I (Praxis)

You didn't set the environment variable CLASSPATH, but a shell variable of this name, i.e. only the shell sees this. What you did here is similar to setting a variable in your Java program, then run a shell program from Java and hope that the Java variable is visible to the shell program.

In shell context, "environment variables" are sometimes also called "exported variables", because the child processes can see them. Each shell has a different way to set an environment variable. For example, bash or zsh use the command export, while csh or tcsh use the command setenv.

You didn't specify, which shell you are using. Consult the man page of your shell to find out, how to set environment variables.

export CLASSPATH=/your/stuff/

or preserving system wide settings:

export CLASSPATH=$CLASSPATH:/your/addition/

the only different from Windows in terms of path-separators, : instead of ;

For example

java -classpath /mydir/mylib.jar:/otherdir/otherlib.jar com.MyProgram -Xmx64m

wildcard in the classpath to add multiple jars

java -cp "Halo.jar:lib/*" ni.package.MainClass

Java Path and Java ClassPath

Anto