Home Man
Today's Posts

Students must use and complete the template provided. If you do not use the template your post may be deleted! Special homework rules apply here.

Java doesn´t find the CLASSPATH (System variable)

classpath, directory, java javac, system variable

Login to Reply

Thread Tools Search this Thread
# 1  
Old 04-19-2016
Java 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.

2. Relevant commands, code, scripts, algorithms:

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

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

see the screenshot.

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

# 2  
Old 09-26-2016
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.
# 3  
Old 02-13-2017
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


Last edited by antoniosarco; 02-13-2017 at 01:28 AM..
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Process not running: /opt/java15/jdk/bin/java -classpath /opt/apache/apache-ant-1.7.0-mod/lib/ant-la gull05 Red Hat 3 04-21-2016 09:46 PM
Solaris: ldd doesn't find libraries in exported environment variable LD_LIBRARY_PATH old_as_a_fossil Solaris 3 12-10-2013 11:25 AM
Fedora java classpath cokedude UNIX for Advanced & Expert Users 0 10-01-2013 08:21 PM
Classpath of JAVA yifangt Programming 1 01-11-2013 06:38 PM
Trouble setting up Java classpath Israel213 Ubuntu 0 03-02-2011 04:18 AM
regarding classpath java PRKS Programming 1 12-24-2009 03:38 AM
exit status running java classpath in unix shell mmcds Programming 2 08-02-2007 10:06 PM
my sgi system doesn't come up siavoush UNIX Desktop Questions & Answers 1 05-16-2005 01:24 PM

All times are GMT -4. The time now is 01:12 PM.

Unix & Linux Forums Content CopyrightŠ1993-2018. All Rights Reserved.
Show Password