Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CLASSPATH environment variable disappears

Status
Not open for further replies.

towerbase

Programmer
Jul 31, 2002
1,053
GB
I am new to Linux and know very little about it.

I have installed Ubuntu (8.04), MySQL and NetBeans (because I want to develop some database applications in Java under Linux).

I have downloaded the MySQL Connector/J jar file into a directory I created called /jconnector. Java needs to know the location of the Connector jar file by means of a CLASSPATH environment variable. I have done this by using
Code:
export set CLASSPATH=/jconnector/mysql-connector-java-5.1.7-bin.jar
However, when I try to connect to JDBC from Java, it fails. So I got my Java program to display the contents of the CLASSPATH environment variable by using the following (Java) code:
Code:
String classp = System.getProperty("CLASSPATH");
System.out.println("CLASSPATH set to " + classp);
The output from this is
CLASSPATH set to null

Yet if I do
Code:
echo $CLASSPATH
at a terminal window, the expected path is displayed correctly.
Presumably my understanding of Linux environment variables is wrong. Can anyone tell me why my Java code doesn't pick up the CLASSPATH environment variable?


Andrew
Hampshire, UK
 
Andrew,

you didn't say whether you're opening different a different window/terminal session to set this parameter. Dependning upon your approach, the parameter might be local to the window and not global; or not otherwise local to the Java session. If your Java session doesn't have the value set but another window shows it, it's likely that the response is accurate.



D.E.R. Management - IT Project Management Consulting
 
Thank you, that sounds promising. I'm used to environment variables always being global as in MSDOS. I must get used to using a proper operating system .... I should be able to find out how to do this now and I'll probably learn a lot on the journey.


Andrew
Hampshire, UK
 
I'm not that familiar with Ubuntu, but generally global items go in /etc/profile (on my distribution /etc/profile is a script that calls other files to set up the environment) or, in my distro, /etc/profile.env (where all the variables actually reside.) You may want to look at these two files.

If you make changes to this you'll need to logout/login for them to take effect; if you just want them to be active immediately in a terminal window you should be able to simply use the command 'source /etc/profile'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top