classpath for jar files

How to set the lib classpath for JAVA program?

I have JAVA program that connect to sql2000 database. It requires a driver (i.e. msbase.jar, mssqlserver.jar, msutil.jar). It is working when I run it with classpath set on the command line, e.g.

javac -classpath ".;./lib/msbase.jar;./lib/mssqlserver.jar;./lib/msutil.jar" MyProgram.java

java -classpath ".;./lib/msbase.jar;./lib/mssqlserver.jar;./lib/msutil.jar" MyProgram

However, it won't work if i move the lib directory to somewhere else and change the above command line to where those .jar located

or

when the "main()" is not on "MyProgram.java", i.e. I have "MyProgram.java" as runnable where the "main()" code calling it.

Is there a better way to set the classpath, i.e. code it into my program so it can find those lib jar files? If so, please advice.

I tried to create "CLASSPATH" environment variable on Windows but it still does not work.

Thanks in advance.

[984 byte] By [tactusa2a] at [2007-10-2 20:22:06]
# 1
My reply here has (or references) the information that you are looking for: http://forum.java.sun.com/thread.jspa?threadID=735358&tstart=0
ChuckBinga at 2007-7-13 23:04:42 > top of Java-index,Desktop,Deploying...