On Mar 13, 11:30 pm, "Mike Schilling" <mscottschill...@hotmail.com>
wrote:
> Joshua Cranmer wrote:
> > Kuki Szabolcs wrote:
>
> >> Please let me know if you find an answer to this question.
> >> I was thinking that it would require a profiler like JRat or
> >> something like that to create a list of classes that were loaded,
> >> during the application run.
>
> >> Then rebuild the jar file with only that list of file.
>
> >> Of course this method is somewhat dangerous because the application
> >> has to be tested with all the possible code paths. Because you might
> >> have somewhere new Class("com.xxxx").newInstance() call which
> >> otherwise is not mapped.
>
> Java classes are always loaded lazily. Even wthout reflective calls,
> different code paths can result in different classes being loaded.
>
>
>
> > The easiest way I can think of is to use the -verbose:class option at
> > runtime and see which classes are listed as loaded.
>
> If you want to do it reliably, you'll need to analyze the class files and
> see which classes they reference (recursively, of course.) This is
> non-trivial.
Actually, it is not that hard. There is a library called ASM from
Objectweb that parses the class files. It is quite easy to create the
dependency graph from this.
I wrote a program for the OSGi headers that makes a dependency graph
but this is based on packages, not classes (OSGi is very focused on
seeing a package as a first class citizen). The program is currently
not creating the payload of the jar from this tree but that would be
quite trivial to add. You can download the code from
http://www.aqute.biz/repo/biz/aQute/...nd-0.0.115.jar. The
source code is in the JAR in the OPT-INF/src directory. This program
actually has its own class file parser.
Kind regards,
Peter Kriens