• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

retrive alla class name in a package

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic