*
The moose likes Other JSE/JEE APIs and the fly likes To Retrive classes from . java file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "To Retrive classes from . java file" Watch "To Retrive classes from . java file" New topic
Author

To Retrive classes from . java file

Nirav Desai
Greenhorn

Joined: Mar 06, 2007
Posts: 2
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

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41062
    
  43
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.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: To Retrive classes from . java file
 
Similar Threads
how to get the information from XML file using xml parser in JSP front end
Vector not accesible in JSP
how to retrive more than one match
Store Java object in MySQL Database
To Retrive classes from . java file