Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

has a way to get all classes in a package?

Thread view: 
aeonsun - 25 Jul 2006 03:24 GMT
I can get the package by Package.getPackage("example"),but i can't get
the classes in the package.
thx!
Jean-Francois Briere - 25 Jul 2006 03:37 GMT
Why do you want that?
aeonsun - 25 Jul 2006 03:43 GMT
I will get the classes dynamically,because i didn't know which new
Class has been add in to the package.
Martin Lansler - 25 Jul 2006 10:05 GMT
Don't think this is possible since the normal java classloader is lazy, i.e.
it only loads classes that are needed... There is no record over all
'avalable' classes.
Perhaps you could try to write your own classloader that scans through JVM
classpath.

Regards,
Martin.
>I will get the classes dynamically,because i didn't know which new
> Class has been add in to the package.
Paul Cager - 27 Jul 2006 00:08 GMT
> I will get the classes dynamically,because i didn't know which new
> Class has been add in to the package.

There isn't a foolproof way to do this, since classes can be loaded from
so many different sources - class files in directories, JARs, URLs etc.
And you could always write your own ClassLoader which might load classes
in a completely new way.

However if you know that your classes will always be in directories
listed in the CLASSPATH then you could use java.io.File to do the
searching - although this will be messy, fragile code. I believe there
is some "standard" tool to do it - have a google of this newgroup and
c.l.j.help as this question comes up quite regularly.

But as Jean-Francois Briere said, "Why do you want to do it?"  There are
often better ways, such as using a properties file.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.