Connecting Tech Pros Worldwide Help | Site Map

Extracting class data from a jar

Tony Burrows
Guest
 
Posts: n/a
#1: Oct 22 '06
I'm building an app which lets users drag and drop classes into a tree,
followed by code generation. For this, I need to have (a) a list of all
the classes which can be dragged and (b) for each class, which of the
others can be a parent in the tree.

All the relevant classes are in a jar file (j3dcore.jar) as well as
other abstract classes and there is standard generated documentation.

Any idea how I could extract the relevant data? Hand coding it would be
just too much.

Tony
Ian Shef
Guest
 
Posts: n/a
#2: Oct 23 '06

re: Extracting class data from a jar


Tony Burrows <tony@tonyburrows.comwrote in
news:pan.2006.10.22.14.31.47.791436@tonyburrows.co m:
Quote:
I'm building an app which lets users drag and drop classes into a tree,
followed by code generation. For this, I need to have (a) a list of all
the classes which can be dragged and (b) for each class, which of the
others can be a parent in the tree.
>
All the relevant classes are in a jar file (j3dcore.jar) as well as
other abstract classes and there is standard generated documentation.
>
Any idea how I could extract the relevant data? Hand coding it would be
just too much.
>
Tony
>
I will have to make some assumptions here, because you:
Didn't describe what this tree represents.
Didn't describe what the parent/child relationship is in the tree.
Didn't describe what is in the jar file.
Didn't describe what "relevant data" means to you.

Assuming that:
The jar file contains .class (or .cla) files.
"Relevant data" means classes, their methods and their fields.

Then java reflection may be the answer to your question.
A jar file can be accessed (doesn't need reflection) to reveal the files
within.
Java reflection allows the classes to be loaded and examined for
information about their methods, fields, etc.

If you need more information, I suggest:

"Java Reflection in Action" (In Action series) by Ira R. Forman and Nate
Forman

I am not associated with the authors or the publisher, just a satisfied
reader.

If I guessed wrong (likely), then please write back with more information.

Good Luck!


--
Ian Shef 805/F6 * These are my personal opinions
Raytheon Company * and not those of my employer.
PO Box 11337 *
Tucson, AZ 85734-1337 *
Mark Rafn
Guest
 
Posts: n/a
#3: Oct 23 '06

re: Extracting class data from a jar


Tony Burrows <tony@tonyburrows.comwrote:
Quote:
>I'm building an app which lets users drag and drop classes into a tree,
>followed by code generation. For this, I need to have (a) a list of all
>the classes which can be dragged and (b) for each class, which of the
>others can be a parent in the tree.
How do you decide which classes can be dragged, and what can be a parent?
Quote:
>All the relevant classes are in a jar file (j3dcore.jar) as well as
>other abstract classes and there is standard generated documentation.
Typically, a combination of requiring the jar to have a specific config file
or manifest in the jar, and use of reflection on classes listed in that config
does the trick.
Quote:
>Any idea how I could extract the relevant data? Hand coding it would be
>just too much.
How would we know what data is relevant? You can use the
java.util.jar.JarFile class to read contents of a jar (including files and
Manifest entries), and java.lang.Class (either from your classloader via
Class.forName(className) or from a URLClassLoader under your control via
loadClass(classBinaryName).

If this tree is known at build-time for the jar, it's really going to be
easiest to put the relevant data into manifest entries or into a specific XML
file in META-INF that you can read and use, rather than guessing based on
looking at every class in the jar.
--
Mark Rafn dagon@dagon.net <http://www.dagon.net/>
Tony Burrows
Guest
 
Posts: n/a
#4: Oct 24 '06

re: Extracting class data from a jar


On Mon, 23 Oct 2006 20:01:10 +0000, Ian Shef wrote:
Quote:
Tony Burrows <tony@tonyburrows.comwrote in
news:pan.2006.10.22.14.31.47.791436@tonyburrows.co m:
>
Quote:
>I'm building an app which lets users drag and drop classes into a tree,
>followed by code generation. For this, I need to have (a) a list of all
>the classes which can be dragged and (b) for each class, which of the
>others can be a parent in the tree.
>>
>All the relevant classes are in a jar file (j3dcore.jar) as well as
>other abstract classes and there is standard generated documentation.
>>
>Any idea how I could extract the relevant data? Hand coding it would be
>just too much.
>>
>Tony
>>
>
I will have to make some assumptions here, because you:
Didn't describe what this tree represents.
Didn't describe what the parent/child relationship is in the tree.
Didn't describe what is in the jar file.
Didn't describe what "relevant data" means to you.
>
Thanks for that, though I finally got as far as using the JarFile class
yesterday.

I was trying to keep things as simple as possible in my query, wrongly.

The actual classes are Java3D ones to build a representation of a J3D
scenegraph, which is a tree (later I'll generate the matching code). The
main classes are all in j3dcore.jar, plus a couple of utility classes.
Other do exist but can't be connected to the scenegraph.

In fact, the classes descend from one of four parents, Group, Leaf,
NodeComponent or unspecified. Leaf nodes can be added to Group nodes so
once I extract the two types I can control what can be dropped where.
NodeComponent nodes can only be dropped on leaf nodes, with 1 exception,
but not all node components on all leaf nodes! The unspecified are
similar. What I've managed is to extract the nodes, but then manually had
to adjust which node components and unspecified objects can be added to
the other nodes, and the numbers allowed (that varies too).

I was trying to avoid the labour of hand coding it all, since the API is
still evolving, but I think it will have to be a blend of the two.

Tony
Closed Thread