Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

retrive alla class name in a package  RSS feed

 
Marco Vanoli
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • 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 ]
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • 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.
 
Marilyn de Queiroz
Sheriff
Posts: 9080
12
  • Mark post as helpful
  • send pies
  • 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 ]
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!