my dog learned polymorphism*
The moose likes Beginning Java and the fly likes add all subfolders to classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "add all subfolders to classpath" Watch "add all subfolders to classpath" New topic
Author

add all subfolders to classpath

seetharaman jayaraman
Ranch Hand

Joined: Feb 18, 2008
Posts: 43
Hi all,
I have classes like below:

c:\proj\main\p1\Class1.class
c:\proj\main\p1\Class2.class
c:\proj\main\p2\Class3.class
c:\proj\main\p2\Class4.class
c:\proj\main\p3\Main5.class

here main, p1,p2 and p3 are packages. if i want to modify classpath for the above classes, i need to do like this:
set classpath=%classpath%;c:\proj\main\p1\;c:\proj\main\p2\;c:\proj\main\p3\;

Here all p1,p2 and p3 are subpackages of "main" package. And when the number of subpackages becomes large, the classpath becomes a big list (like a paragraph!!). Is there any way simplify this i.e to include all subpackages of main package.

Thanks


Seetharaman Jayaraman
Only Change is Changeless
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

So, class Class1 is in a package called main.p1?

If so, you don't need to add all those sub folders to the class path - c:\proj\ is enough. When the JVM needs to load class main.p1.Class1, it will try looking for a file main\p1\Class1.class relative to all folders in the class path. So if your class path includes ".", "D:\" and "c:\proj\", it will try ".\main\p1\Class1.class" first, "D:\main\p1\Class1.class" next and finally ""c:proj\main\p1\Class1.class".


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
seetharaman jayaraman
Ranch Hand

Joined: Feb 18, 2008
Posts: 43
I tried many ways. By fluke, a dot (".") solved the problem. i.e, the main package is "main" under c:\proj\ folder. p1, p2 and p3 are under this "main" package. I set classpath like the one below (added a dot after "c:\proj\") which solved the problem:
set classpath=%classpath%;c:\proj\.;

This includes all sub folders (sub packages) to the classpath.

Also thanks Rob Prime.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: add all subfolders to classpath