How can identify Applet subclasses from a Jar file?

无人久伴 提交于 2020-01-06 22:44:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!