Witam
jak w paczce JAR mogę podejrzeć daną klasę ? jej źródła
Witam
jak w paczce JAR mogę podejrzeć daną klasę ? jej źródła
Nie możesz
Jeżeli nie ma załączonych źródeł to nie możesz tego zrobić. Są jednak pewne metody, które pozwalają na odgadnięcie co klasa robi. Tak mniej więcej :D
mamy sobie taką klasę:
public class AppTest extends TestCase {
/**
* Create the test case
*
* @param testName
* name of the test case
*/
public AppTest(String testName) {
super(testName);
}
/**
* @return the suite of tests being tested
*/
public static Test suite() {
return new TestSuite(AppTest.class);
}
/**
* Rigourous Test :-)
*/
public void testApp() {
assertTrue(true);
}
}
Po skompilowaniu na pliku class wykonujemy javap -verbose i:
Compiled from "AppTest.java"
public class pl.k.jtuples.AppTest extends junit.framework.TestCase
SourceFile: "AppTest.java"
minor version: 0
major version: 50
Constant pool:
const #1 = class #2; // pl/k/jtuples/AppTest
const #2 = Asciz pl/k/jtuples/AppTest;
const #3 = class #4; // junit/framework/TestCase
const #4 = Asciz junit/framework/TestCase;
const #5 = Asciz <init>;
const #6 = Asciz (Ljava/lang/String;)V;
const #7 = Asciz Code;
const #8 = Method #3.#9; // junit/framework/TestCase."<init>":(Ljava/lang/String;)V
const #9 = NameAndType #5:#6;// "<init>":(Ljava/lang/String;)V
const #10 = Asciz LineNumberTable;
const #11 = Asciz LocalVariableTable;
const #12 = Asciz this;
const #13 = Asciz Lpl/k/jtuples/AppTest;;
const #14 = Asciz testName;
const #15 = Asciz Ljava/lang/String;;
const #16 = Asciz suite;
const #17 = Asciz ()Ljunit/framework/Test;;
const #18 = class #19; // junit/framework/TestSuite
const #19 = Asciz junit/framework/TestSuite;
const #20 = Method #18.#21; // junit/framework/TestSuite."<init>":(Ljava/lang/Class;)V
const #21 = NameAndType #5:#22;// "<init>":(Ljava/lang/Class;)V
const #22 = Asciz (Ljava/lang/Class;)V;
const #23 = Asciz testApp;
const #24 = Asciz ()V;
const #25 = Method #1.#26; // pl/k/jtuples/AppTest.assertTrue:(Z)V
const #26 = NameAndType #27:#28;// assertTrue:(Z)V
const #27 = Asciz assertTrue;
const #28 = Asciz (Z)V;
const #29 = Asciz SourceFile;
const #30 = Asciz AppTest.java;
{
public pl.k.jtuples.AppTest(java.lang.String);
Code:
Stack=2, Locals=2, Args_size=2
0: aload_0
1: aload_1
2: invokespecial #8; //Method junit/framework/TestCase."<init>":(Ljava/lang/String;)V
5: return
LineNumberTable:
line 18: 0
line 19: 5
LocalVariableTable:
Start Length Slot Name Signature
0 6 0 this Lpl/k/jtuples/AppTest;
0 6 1 testName Ljava/lang/String;
public static junit.framework.Test suite();
Code:
Stack=3, Locals=0, Args_size=0
0: new #18; //class junit/framework/TestSuite
3: dup
4: ldc #1; //class pl/k/jtuples/AppTest
6: invokespecial #20; //Method junit/framework/TestSuite."<init>":(Ljava/lang/Class;)V
9: areturn
LineNumberTable:
line 26: 0
public void testApp();
Code:
Stack=1, Locals=1, Args_size=1
0: iconst_1
1: invokestatic #25; //Method assertTrue:(Z)V
4: return
LineNumberTable:
line 34: 0
line 35: 4
LocalVariableTable:
Start Length Slot Name Signature
0 5 0 this Lpl/k/jtuples/AppTest;
}
Do przemyślenia pozostawiam co odpowiada czemu. Warto poczytać dokumentację.
wielkie dzięki Koziołek
Albo uzyj dekompilatora ;)