A
aidy
Is there a way to find all the public static main methods in a given
set of classes/archives?
Aidy
set of classes/archives?
Aidy
Is there a way to find all the public static main methods in a given
set of classes/archives?
Aidy
aidy said:Is there a way to find all the public static main methods in a given
set of classes/archives?
zero said:If you want to find them in compiled classes, try any one of a thousand hex
editors.
Shorty said:And probably other java IDE too.
In eclipse, I guess you'll be looking into "java search"...
Shorty said:If programmaticcaly is what you need, you'll also need to change the
second parameter, since main takes in a String[] not a String. I don't
quite remember the exact syntax to use arrays that way and don't have
the means to try here, so you'll have to give more hints.
Is there a way to find all the public static main methods in a given
set of classes/archives?
Shorty said:However, be aware that you can only do this on classes that you can
actually load in a JVM, meaning they are in the classpath or you have a
classloader that can load them. you can't just use that directly on any
class in your filesystem.
If you are looking at compiled classes, then it'd be better, for several
reasons, to use a byte-code library such as BCEL or ASM for the scanning.
Reasons:
+) Probably faster (I haven't checked but it /ought/ to be).
+) Safer (no risk of class initialisation code running).
+) More flexible (as you say, no need for the .class file to be on the
classpath).
Downside:
-) You have to learn (a bit about) BCEL or ASM[*].
-) ?
-- chris
([*] a couple of people in this group have recently stated their
preference for
ASM over BCEL; on the whole I think they're probably right -- not that
I've
played much with either package -- but I suspect that the BCEL API is
more
straightforward for the occasional user than ASM's Visitor pattern based
API)
[...]Ross said:<(free) product placement>
[...]Ross said:<(free) product placement>
<grin>
My apologies, I had forgotten all about Jen (odd since I read about it
only a
couple of weeks ago). In mitigation I offer the excuse that I hadn't
realised
that Jen was supposed to ease reading classfiles as well as writing them.
-- chris
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.