Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

To Retrive classes from . java file

 
Nirav Desai
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ppl.....
i hav got a query.... of how to retrive which all classes are present in . java file... i.e i want the name of the the classes in a . java file...........

actually my original problem is that at runtime i want to find out the class that contain the main() in a . java file...
hope it wil b solved
thanks in advance.....
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you need to parse the file with some sort of regular expression to match the pattern you are after. java.io.* and java.util.regex.* should help.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is tricky, as there is no one particular string you can look for. Even using regexps there are quite few possibilities of how a main method might look like. It would be easier to do this with class files instead of source files, since you can use reflection to look for the one signature that indicates a main method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic