aspose file tools
The moose likes Java in General and the fly likes adding jar or directory to classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "adding jar or directory to classpath" Watch "adding jar or directory to classpath" New topic
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.



 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: adding jar or directory to classpath
 
Similar Threads
compiling
Path/Classpath Problem
hibernate and eclipse
junit classpath issue, I think
loading properties into the classpath