• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

add all subfolders to classpath

 
seetharaman jayaraman
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
seetharaman jayaraman
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic