How to use CLASSPATH

My program need a jar file, let see test.jar. I use java -cp to indicate the CLASSPATH. Why must I point to the test.jar? Why can't I point a directory which contains the jar file?

For example, when i use:

java -cp /test/test.jar:. MyProgram// it works fine

But when I use:

java -cp /test:. MyProgram// an error indicating can't find a class will be shown

[388 byte] By [youhaodiyia] at [2007-11-27 9:36:16]
# 1
Why must your mail be addressed to you? Why can't it just be addressed to your street?
georgemca at 2007-7-12 23:04:57 > top of Java-index,Desktop,Deploying...
# 2
According to the help message:-cp <class search path of directories and zip/jar files>It says -cp can point to a directory.Message was edited by: youhaodiyi
youhaodiyia at 2007-7-12 23:04:57 > top of Java-index,Desktop,Deploying...
# 3

> According to the help message:

> -cp <class search path of directories and zip/jar

> files>

> It says -cp can point to a directory.

>

> Message was edited by:

> youhaodiyi

Yes, you are right. It can point to a directory. But the directory have to contain the file structure of your application. This means the given directory is used as a virtual jar-file and not as directory itself.

For example you have two packages

com.test1

and

com.test2

So the target file structure must be

C:\myjar\com\test1

C:\myjar\com\test2

So you could launch like

java -cp C:\myjar\ com.TestClass

I hope it helps you to understand the meaning of using the classpath.

alexra at 2007-7-12 23:04:57 > top of Java-index,Desktop,Deploying...