简体   繁体   中英

how can i set classpath for external jar files in java?

I am using java1.6 without using any IDE.Now i want to use java Mail API for my purpose.So, i copied Mail.jar into d:\\externaljar folder.

And also i have set the classpath as set classpath=%classpath%;d:\\externaljar;

my jdk installation folder is : c:\\programfiles\\jdk1.6 .

But i faced package javax.mail does not exist during compilation.

Please Guide me to get out of this issue?

The jar file itself must be in the classpath, and not just the directory containing it.

And the CLASSPATH environment variable is CLASSPATH , not classpath . My advice would be to never use it, though. Always use the -classpath (or -cp ) option with javac or java to pass the classpath.

与全局CLASSPATH环境变量相比,我更喜欢-cp选项:

java -cp .;d:/externaljar/mail.jar my.application.App

I'd recommend against setting CLASSPATH and instead use the -cp flag:

javac -cp .;d:\externaljar\mail.jar whatever/package/YourClass.java

You may also use wildcarding:

javac -cp .;d:\externaljar\* whatever/package/YourClass.java

Running is the same thing, except you provide the classname with the main method.

java -cp .;d:\externaljar\* whatever.package.YourClass

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM