How to find the main java class file

I need to write a Java program which MUST know one of these:

1) the full path to the main java class (the class with "main" method)

or

2) access to the main class as byte array.

If i know (1) then I have no problems reading the main class into byte array, but the main target is still (2).

Another option is if the main file is in JAR, which again leads to problems, because I cannot access the file in normal way, but I still need access to the exact byte stream.

Any help is highly appreciated! Thanks!

<<< Ivan Davidov >>>

[592 byte] By [Ivan_Davidova] at [2007-11-27 7:01:34]
# 1
You could try somthing like this in your main-method:InputStream is = getClass().getResourceAsStream(<"myModifiedPackageName/MyClass.class">);I don't know if this works though.Have a look at the API doc for this method.-Puce
Pucea at 2007-7-12 18:52:25 > top of Java-index,Java Essentials,Java Programming...
# 2
Actually getResource() called from a class object uses a path relative to the package, so that:InputStream is = MyClass.class.getResourceAsStream("MyClass.class");should do the trick. This will work whether you're in a jar or not.
malcolmmca at 2007-7-12 18:52:25 > top of Java-index,Java Essentials,Java Programming...
# 3
Thanks, I tried the last suggestion and it worked!
Ivan_Davidova at 2007-7-12 18:52:25 > top of Java-index,Java Essentials,Java Programming...