• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

class path question

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
-classpath /com:/foo:.
is not the same as
-classpath .:/foo:/com


Can anyone explain the difference. k&b 798 page.(unable to understand).
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

-classpath /com:/foo:.
is not the same as
-classpath .:/foo:/com



They are not same.


Whenever javac or java is invoked using -classpath /com:/foo:.
it will look for the required classes in /com first. If not found, it goes to /foo and look for the same. If not found, it searches the current directory.

If it managed to find in /com it won't search inside /foo. Similarly, if it cannot find in /com but managed to find the class in /foo, it won't search in the current directory. Again if the class is not found in /foo, it will search in the current directory. If the class is not found in the current directory, the compilation will fail.

So in .:/foo:/com, the sequence of searching the class file starts from current directory. If not found in the current directory, it goes to the /foo. If not found in /foo, then it look in the /com.

Again, if it managed to find in the current directory, it stops there. The process continues to /foo if the class is not available in the current directory. The /com will be searched if the class file is not available in the /foo directory. If the class file is not found in the /com directory, then the compilation will fail.

HTH.

_charles
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just read the sentence above it . Because the classpath is read from left to right the class that is first found will be used.

Example:

ClassPathTest.java

test1/Child.java

test2/Child.java


java -cp .:test1/:test2/ ClassPathTest
Output: test1/Child.java
java -cp .:test2/:test1/ ClassPathTest
Output: test2/Child.java
 
Rajiv Chopra
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Wouter Oet wrote:Just read the sentence above it . Because the classpath is read from left to right the class that is first found will be used.

Example:

ClassPathTest.java

test1/Child.java

test2/Child.java


java -cp .:test1/:test2/ ClassPathTest
Output: test1/Child.java
java -cp .:test2/:test1/ ClassPathTest
Output: test2/Child.java



Thanks you very much! I am using windows so i think : should be ; for me.

Thanks for both comments above again.
 
reply
    Bookmark Topic Watch Topic
  • New Topic