Unix/Linux Go Back    


Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here.

Java doesn´t find the CLASSPATH (System variable)

Homework & Coursework Questions


Tags
classpath, directory, java javac, system variable

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-19-2016
MenschTown MenschTown is offline
Registered User
 
Join Date: Apr 2016
Last Activity: 20 April 2016, 6:21 AM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
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)
Attached Thumbnails
Java doesn´t find the CLASSPATH (System variable)-problem-png  
Sponsored Links
    #2  
Old Unix and Linux 09-26-2016
rovf rovf is offline
Registered User
 
Join Date: Jun 2011
Last Activity: 26 May 2017, 4:56 PM EDT
Posts: 162
Thanks: 22
Thanked 29 Times in 25 Posts
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.
Sponsored Links
    #3  
Old Unix and Linux 02-13-2017
antoniosarco antoniosarco is offline
Registered User
 
Join Date: Feb 2017
Last Activity: 13 February 2017, 1:28 AM EST
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
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

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
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



All times are GMT -4. The time now is 08:43 PM.