This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes retrive alla class name in a package Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "retrive alla class name in a package" Watch "retrive alla class name in a package" New topic
Author

retrive alla class name in a package

Marco Vanoli
Ranch Hand

Joined: Jan 12, 2005
Posts: 99
How can i do if i need to put in an array (or list) all class name of a package.

Ex. Package Gomez<--class Ginoz
<--class Pinoz

I needemethd as: xx.method(Gomez) <-- this gimme String Ginoz & Pinoz strings

tnks
[ September 11, 2005: Message edited by: Marco Vanoli ]

bye, <br />Marco
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
You cannot know all classes in a package simply because the total number of them is infinity. You can determine all classes that have been loaded by using your own bootstrap classloader, or using your own agent that keeps a registry of loaded classes (see java.lang.instrumentation). You can also determine all packages (java.lang.Package) that have been loaded by a specific loader using Package.getPackages()

I can't make sense of the remainder of your question.


Tony Morris
Java Q&A (FAQ, Trivia)
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9033
    
  10
Originally posted by Marco Vanoli:
I needemethd as: xx.method(Gomez) <-- this gimme String Ginoz & Pinoz strings

If you are asking how to add the name to the List, I suggest you used the add() method of the List class.
[ September 11, 2005: Message edited by: Marilyn de Queiroz ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 681
In general to get all the classes in a package THAT is on your classpath, you would need to have a routine that uses something like the File.list() method that would return all the files in a directory and then go thru them to find any files with paths that match the package you are looking for. The routine would have to be recursive (ie be able to go into sub folders) and also it would have to be able to read jar files.

What is the application that needs this information?
Marco Vanoli
Ranch Hand

Joined: Jan 12, 2005
Posts: 99
I' having to do a struts form. In one field i must find a list of differnt class name and then when choosed one i can modify some parameters about it saving them on database. These classes belong to another project in the same build path.
My it' s a web application that configure the other one.

I can make a String list of that classes name but is more nice to have a runtime check & create the list
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: retrive alla class name in a package
 
Similar Threads
taglib descriptor questions?
unable to deploy servlets in tomcat
Problem viewing applet in Firefox 2 on Ubuntu Linux
problem implementing EL function example from HFS&J :page 389
Error: IllegalName: /SearchServlet