| Author |
adding jar or directory to classpath
|
Raj Ohadi
Ranch Hand
Joined: Jun 30, 2006
Posts: 314
|
|
I have questions about classpath --
1. what's the difference between adding some jar as "pre-fix to classpath" and adding jars as "appending to classpath" ? In Eclipse ideas there are such options. But, if you just want to add a .jar file to your classpath, what's the difference of pre-fixing it or suffix-ing it at the end of classpath ?
2. WHy people sometimes need to add a directory to classpath ? Can someone give an example ? I thought we would only need to add .jar files... If I put the 10 .jar files under one directory, then can I just add that directory into claspath or do I have to add the 10 .jar files one by one into classpath ?
Thanks.
|
 |
Balu Sadhasivam
Ranch Hand
Joined: Jan 01, 2009
Posts: 874
|
|
Raj ,
2. WHy people sometimes need to add a directory to classpath ? Can someone give an example ? I thought we would only need to add .jar files... If I put the 10 .jar files under one directory, then can I just add that directory into claspath or do I have to add the 10 .jar files one by one into classpath ?
CLASSPATH is where your application searches for any classes and resources like properities ( especially when loaded by Classloader) , and hence if you provide just directory , the .class file is searched with the package structure.
Say Class X is inside package com, then your classpath must include your top level directory , which is the directory directly above com.
And if classes are packaged inside jar , then Jars must be included in the classpath to indicate the Compiler to use the jar for class loading.
1. what's the difference between adding some jar as "pre-fix to classpath" and adding jars as "appending to classpath" ? In Eclipse ideas there are such options. But, if you just want to add a .jar file to your classpath, what's the difference of pre-fixing it or suffix-ing it at the end of classpath ?
This is will not affect in any sense unless you have duplicate Class entries in the CLASSPATH. ClassLoader loads the first encountered class from the CLASSPATH.
|
 |
 |
|
|
subject: adding jar or directory to classpath
|
|
|