Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How to retrieve constants value from compiled code in jar file?

Reply
Thread Tools

How to retrieve constants value from compiled code in jar file?

 
 
lilisbbcsweet@googlemail.com
Guest
Posts: n/a
 
      07-06-2007
Hi everyone,

I've been looking for a way to solve this for a week now, without any
much success... and I've finally decided to ask the Java gurus for a
solution!
Here's what I am basically trying to do:
I have several jar files in which there are only compiled code
(.class).
In every class, there are 2 constants (declared as static final
String) that I would like to retrieve (one is the version and the
other the date of the last modification).
My goal is to print a list of all the classes in the jar files with
the values of these 2 constants for each class.

The solution that I have right now to do this does not work properly:
for now, I read all the elements of the classpath, check if these are
jar files, and if so, I look into each one and load all the classes
one by one and print the results.
The problem with this is that it uses the method
Class.forName(className) and as some classes are unfortunately present
in many jar files (2 or 3 copies), once the classes have been loaded,
then it won't be "reloaded".
Without the possibility to "reload" these classes, I cannot see
inconsistencies in the versions of the classes present in the jar
files.

I have read many articles, and I thought that I could then use a
custom classloader and create a new instance of this classloader for
each jar file.
2 problems with this:
- according to many posts in the different forums I have read, the jar
files should not appear in the CLASSPATH (but this would be easier for
me if I could use it...)
- some classes will not be loaded if some classes (present in other
jar files) are not loaded... and this makes things really really
complicated to implement...

So, I thought that I was maybe doing this the wrong way, and that
there might be an easy way out of this...
In fact, I do not need to load the classes... all I need to do, is
take a sneak peek at the constants and print their values... and
that's it!
Somehow, I think that this is possible to retrieve the values of
compile time constants (declared as static final String) as I can see
that with Eclipse (when opening a jar file).
So, my question is: how can I do that within my java application?
Or maybe there is another easier solution to do what I need?

Thanks in advance for your help!

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      07-06-2007
On Fri, 06 Jul 2007 14:11:30 -0000,
wrote, quoted or indirectly quoted someone who said :

>I've been looking for a way to solve this for a week now, without any
>much success... and I've finally decided to ask the Java gurus for a
>solution!


I have a number of similar student projects posted with suggestions on
how to solve them. See
http://mindprod.com/projects/interfacefinder.html

That is pretty close to what you want to do.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
If I create a page, then it's compiled upon first request, where cani find the compiled code?? lander ASP .Net 5 03-05-2008 04:34 PM
jaas.jar, jta.jar jdbc-stdext.jar missing from jdk1.5 RPM muttley Java 0 10-20-2005 02:40 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters Java 0 01-05-2005 10:59 PM
g++ compiled C++ code called from gcc compiled C code Klaus Schneider C++ 1 12-02-2004 01:44 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57