Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve the list of loaded/used classes in a java applet

Status
Not open for further replies.

phuiphch

Programmer
May 22, 2002
2
CH
We are working on an applet that handles/displays XML based content. We could not use Microsofts XML parser because the application has to run on different browsers and operating systems. We used suns XML implementation and use it in the applet to perform several transformations. In this way we have a platform independent XML parser. The disadvantage is that the packed cab/jar is big (around 700kb). We do not use all the functionality so some of the classes could be deleted from the package.

The question is now how to identify the classes that are really used in the applet? We tried to implement a custom classloader but did not succeed. What we want is to hook into the normal classloader and get the name of the loaded call, put them into a list and get this list into a file.

Is there another way to retrieve the list of loaded/used classes or can someone give us a hint how the custom classloader has to be hook into the native classloader?

Any help would be highly appreciated.
Philipp

<code>
public class sycomW extends Applet
{
private sycom s;
public void init() {
try {
MyClassLoader myClassLoader = new MyClassLoader();
s = (sycom) myClassLoader.loadClass(&quot;sycom&quot;).newInstance();
} catch (InstantiationException e) {System.out.println(&quot;InstantiationException&quot;);
} catch (IllegalAccessException i) {System.out.println(&quot;(IllegalAccessException&quot;);
} catch (ClassNotFoundException c) {System.out.println(&quot;ClassNotFoundException&quot; + c);
}
}

public class MyClassLoader extends ClassLoader
{
protected MyClassLoader()
{
super();
}

protected Class findClass(String name) throws ClassNotFoundException
{
System.out.println(&quot;findClass: &quot; + name);
return super.findClass(name);
}

public Class loadClass(String name) throws ClassNotFoundException
{
System.out.println(&quot;Load class: &quot; + name);
super.loadClass(name);
return Class.forName(name);
}

protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException
{
System.out.println(&quot;Load classA: &quot; + name);
return Class.forName(name);
}
}
</code>
 
The nature of XML is that you cannot say what classes you need because they depend from the XML content. We would like to start the applet, go through the whole content and after this see what classes have been used from the java XML package.

Philipp
 
I posted a similar question a few days ago. Perhaps you might want to have a look.

thread269-274334
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top