Finding classes used by Applet

N

Novice

Is there a simple and reliable technique for determining the classes needed
for an applet jar?

In other words, if I want to put Applet X in a jar, how do I determine all
of the classes I'm using in the Applet - directly or indirectly but
excluding the Oracle Java classes - which I wrote.

Currently, I'm doing it by inspection. I look at the imports in the applet,
then look at the other classes referenced in the code which aren't in the
import list and then see what they depend on. This is a slow and error-
prone approach. I'll bet there is a simpler way to do it.

I'm using Eclipse 3.7. Is there a built-in facility to do what I want in
Eclipse? If so, what is it called and where do I find it? Or is there a
plug-in that determines dependencies which I can add to Eclipse?
 
R

Roedy Green

Is there a simple and reliable technique for determining the classes needed
for an applet jar?

see http://mindprod.com/jgloss/genjar.html
http://mindprod.com/jgloss/ant.html

If that terrifies you, can run your Applet as an application
see http://mindprod.com/jgloss/hybrid.html
with the option that names each class as it is loaded.
see http://mindprod.com/jgloss/javaexe.html
--
Roedy Green Canadian Mind Products
http://mindprod.com
It should not be considered an error when the user starts something
already started or stops something already stopped. This applies
to browsers, services, editors... It is inexcusable to
punish the user by requiring some elaborate sequence to atone,
e.g. open the task editor, find and kill some processes.
 
N

Novice


Well, I won't say that it terrifies me but it does seem a bit like asking
for a rowboat and being given the Queen Mary....
can run your Applet as an application
see http://mindprod.com/jgloss/hybrid.html

That sounds very interesting but the link for 'hybrid' doesn't work. I also
tried looking for "Hybrid" in your index but came up empty. I'm guessing
there is a typo in the URL.....
with the option that names each class as it is loaded.
see http://mindprod.com/jgloss/javaexe.html

I skimmed that page but didn't see anything that looked like it would tell
me what classes were needed for my applet....
 
J

Jef

search the word Hybrid in the page
http://mindprod.com/jgloss/applet.html

java -verbose will print lines like
[Loaded java.lang.Object from /opt/jdk1.6.0_07/jre/lib/rt.jar]
[Loaded java.io.Serializable from /opt/jdk1.6.0_07/jre/lib/rt.jar]
[Loaded java.lang.Comparable from /opt/jdk1.6.0_07/jre/lib/rt.jar]
....
It gives you the class files that are loaded, but you need to pass
through all the features of your program in order to be sure you have
loaded all the needed classes.

genjar is probably the cleaner solution.
 
D

David Lamb

search the word Hybrid in the page
http://mindprod.com/jgloss/applet.html

java -verbose will print lines like
[Loaded java.lang.Object from /opt/jdk1.6.0_07/jre/lib/rt.jar]
[Loaded java.io.Serializable from /opt/jdk1.6.0_07/jre/lib/rt.jar]
[Loaded java.lang.Comparable from /opt/jdk1.6.0_07/jre/lib/rt.jar]
...
It gives you the class files that are loaded, but you need to pass
through all the features of your program in order to be sure you have
loaded all the needed classes.

It probably makes sense to create some collection of test cases to run
through all the features anyway, whether or not you need the list for
the OP's purpose.
 
R

Roedy Green

That sounds very interesting but the link for 'hybrid' doesn't work. I also
tried looking for "Hybrid" in your index but came up empty. I'm guessing
there is a typo in the URL...

try http://mindprod.com/jgloss/applet.html#SWITCHHITTER
--
Roedy Green Canadian Mind Products
http://mindprod.com
It should not be considered an error when the user starts something
already started or stops something already stopped. This applies
to browsers, services, editors... It is inexcusable to
punish the user by requiring some elaborate sequence to atone,
e.g. open the task editor, find and kill some processes.
 
R

Roedy Green

genjar is probably the cleaner solution.

Once you have figured out GenJar, the problem goes away completely
ever after. If you collect lists of classes, the problem will continue
to haunt you and will need constant tweaking.

It is a bit like learning to touch type. It is a hurdle to get over,
but ever after you can type much faster.

Jef and I both think your are better off using Genjar.

Just read one of my Ant Scripts. Prune out what you understand and
definitely do not need. Anything you don't understand yet, just leave
alone. Let GenJar do its magic. You will be amazed at how quickly it
solves this problem that makes you butt your head against the wall.
--
Roedy Green Canadian Mind Products
http://mindprod.com
It should not be considered an error when the user starts something
already started or stops something already stopped. This applies
to browsers, services, editors... It is inexcusable to
punish the user by requiring some elaborate sequence to atone,
e.g. open the task editor, find and kill some processes.
 
R

Roedy Green


I have added hybrid to the index as an alias for that entry
--
Roedy Green Canadian Mind Products
http://mindprod.com
It should not be considered an error when the user starts something
already started or stops something already stopped. This applies
to browsers, services, editors... It is inexcusable to
punish the user by requiring some elaborate sequence to atone,
e.g. open the task editor, find and kill some processes.
 
A

Arne Vajhøj

Is there a simple and reliable technique for determining the classes needed
for an applet jar?

In other words, if I want to put Applet X in a jar, how do I determine all
of the classes I'm using in the Applet - directly or indirectly but
excluding the Oracle Java classes - which I wrote.

Currently, I'm doing it by inspection. I look at the imports in the applet,
then look at the other classes referenced in the code which aren't in the
import list and then see what they depend on. This is a slow and error-
prone approach. I'll bet there is a simpler way to do it.

I'm using Eclipse 3.7. Is there a built-in facility to do what I want in
Eclipse? If so, what is it called and where do I find it? Or is there a
plug-in that determines dependencies which I can add to Eclipse?

This is an unusual problem.

Usually you pack all class files from the project into a jar file
and distribute it with the same jar files used for build (and
often a few more jar files needed to run).

Stuff not needed should not be in the project.

But let us assume that you for whatever reason need to do it.

The java command has an option to display classes loaded, but
that may not work well for an applet, so you may need to write
a console app wrapper.

Alternatively you can cheat a bit and use the following:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
System.setOut(new PrintStream(baos));
ClassLoadingMXBean jmx = ManagementFactory.getClassLoadingMXBean();
jmx.setVerbose(true);
// do whatever
String s = baos.toString();

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
anuragag27

Latest Threads

Top