• Post Reply Bookmark Topic Watch Topic
  • New Topic

adding jar or directory to classpath  RSS feed

 
Raj Ohadi
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!