问题
I have the two following class hierarchy in jar files where the only difference is that Main
in example2.jar has no package while Main
in example1.jar is part of the package user
.
example1.jar
// user/Main.java
package user;
import Engine.GameWindow;
public class Main extends GameWindow { }
// Engine/GameWindow.java
package Engine;
import java.applet.Applet;
public abstract class GameWindow extends Applet { }
example2.jar
// Main.java
import Engine.GameWindow;
public class Main extends GameWindow { }
// Engine/GameWindow.java
package Engine;
import java.applet.Applet;
public abstract class GameWindow extends Applet { }
I created this program to determine which classes inside of a jar file are subclasses of Applet.
import java.applet.Applet;
public class JarClassIdentifier
{
public static void main(String[] args)
throws Exception
{
// example1.jar: args = { "user.Main.class", "Engine.GameWindow.class" }
// example2.jar: args = { "Main.class", "Engine.GameWindow.class" }
for(String class_name : args) {
class_name = class_name.replace(".class", "");
Class<?> c = Class.forName(class_name);
if(Applet.class.isAssignableFrom(c))
System.out.println(class_name);
}
}
}
For example1.jar, the program correctly prints user.Main
and Engine.GameWindow
. Why does example2.jar only print out Engine.GameWindow
?
来源:https://stackoverflow.com/questions/20579579/how-can-identify-applet-subclasses-from-a-jar-file