0

Is there a way to determine the starting point of a java applet given just the jar file? I'm trying to create a website where I can upload an applet's jar file and then play it back with something similar to the following.

<object type="application/x-java-applet" height="450" width="450">
  <param name="code" value="<? echo $startingClass; ?>" />
  <param name="archive" value="<? echo $jarUrl; ?>" />
  Applet failed to run.
</object>

The applet's I've been given do not have correct manifest or jnlp files. I've tried using jar -tvf 'jarfile.jar' to get a list of all of the classes in the jar file, but can't determine which one is the entry point.

Any help is appreciated!

Boris Brodski
  • 8,425
  • 4
  • 40
  • 55
pLiKT
  • 120
  • 1
  • 1
  • 9

3 Answers3

1

Sounds very complicated to me. Roughly I think this is needed:

  1. after upload of the jar on the server, you would need a custom class loader to load the jar on your server (see Load jar dynamically).
  2. Then you can use Reflection to find applet main class in it,
  3. then you would redirect to a JSP where you can generate the needed <object> tag.
Community
  • 1
  • 1
geert3
  • 7,086
  • 1
  • 33
  • 49
1

.. but can't determine which one is the entry point.

Use something like:

if (exampleOfClass instanceof Applet) { // We're good to go!...
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • How would I go about using the information from the string "pac/kage/ClassName.class" to get a class that I can check the instance of? – pLiKT Dec 14 '13 at 00:36
  • Ah, I can use Class.forName("pac.kage.ClassName") to get the class. Very cool! I'm not able to instantiate an actual object, but Applet.class.isAssignableFrom seems to work. – pLiKT Dec 14 '13 at 01:43
0

Here is a partial solution based on the other comments, but I ran into an issue where not all subclasses of applet were being identified (How can identify Applet subclasses from a Jar file?). The program will print out the classes inside the Jar file that are a subclass of Applet. One of those classes (possibly the most-derived class) is the entry point.

import java.applet.Applet;

public class JarAppletIdentifier 
{  
  public static void main(String [] args)
    throws Exception
  {
    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);
    }   
  }
}

This snippet expects as arguments the list of classes in the jar file.

Using linux, the arguments can be read from the jar file and parsed using

// prints out, eg. 
//   pac.kage.Main.class
//   pac.kage.Other.class
//   user.pac.kage.SomeClass.class
jar_classes=$(jar -tf example.jar | 
  grep .class | grep -v "\\$" | grep -v "^\." | sed 's/\//\./g')

You can then pass this result into the program with

echo $jar_classes | xargs java -classpath "example.jar" JarAppletIdentifier
Community
  • 1
  • 1
pLiKT
  • 120
  • 1
  • 1
  • 9