Re: Extracting class data from a jar



Tony Burrows <tony@xxxxxxxxxxxxxxx> wrote:
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?

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.

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@xxxxxxxxx <http://www.dagon.net/>
.



Relevant Pages

  • Re: Reflection: Instantiate All Classes in a Package?
    ... Each class will exist in the same package. ... A jar is a searchable location. ... configuration file where a developer adds the name of his class to the ... The config file will be faster than scanning the jar, ...
    (comp.lang.java.programmer)
  • Re: Reflection: Instantiate All Classes in a Package?
    ... Each class will exist in the same package. ... A jar is a searchable location. ... configuration file where a developer adds the name of his class to the ... The config file will be faster than scanning the jar, ...
    (comp.lang.java.programmer)
  • Does load-on-startup effect tomcat singleton classloading?
    ... That jar has a servlet, loaded at startup, which loads a config file ... Each war overwrites the others singleton config. ... I am absolutely sure the jar is in no ther place. ... but perhaps a servlet loaded on startup changes ...
    (comp.lang.java.programmer)
  • Re: Current path
    ... Use the config file only read-only as your app might ... When you deliver an default config in your jar ... installation. ...
    (comp.lang.java.programmer)