This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
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 Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "add all subfolders to classpath" Watch "add all subfolders to classpath" New topic

add all subfolders to classpath

seetharaman jayaraman
Ranch Hand

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


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.


Seetharaman Jayaraman
Only Change is Changeless
Rob Spoor

Joined: Oct 27, 2005
Posts: 20128

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".

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:
subject: add all subfolders to classpath
It's not a secret anymore!