Re: programmatic way for detecting imports....
From: John C. Bollinger (jobollin_at_indiana.edu)
Date: 05/14/04
- Next message: Bent C Dalager: "Re: load virtual machine once in windows ?"
- Previous message: Simon Brooke: "Repacking jar files..."
- In reply to: MB: "programmatic way for detecting imports...."
- Next in thread: Neal Gafter: "Re: programmatic way for detecting imports...."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 14 May 2004 09:38:06 -0500
MB wrote:
> I need to load a jar file and analyze it analyze it as follows. (I
> need a programmatic way for this)
>
> 1) for each class in a jar see what are the imports for that class.
> (if I can get a list of imports with what are the methods that are
> imported, then it will be good)
It is not possible to determine by analysis of a class file what
"import" statements were in the corresponding source file (if there was
one). The "import" statement is a Java feature that provides
convenience for programmers but has no representation in bytecode.
You may, however, really mean that you want to dynamically find a class'
dependencies on other classes. This has little to do with import
statements in the source code, but it is more likely to be a sensible
thing to do. Check out Roedy's response, and don't neglect the cross
references near the bottom of the page he points you to.
> 2) find if the imports are in the current class path or not.
The easiest way to determine whether a specific class is in a specific
class path is to attempt to load it. You can create a URLClassLoader
instance distinct from that for the running application to perform the
class loading without risking any interference with your checker app.
> I think it should be possible as Eclipse does this whenever you load a
> jar file.
Eclipse certainly does detect when your project depends on classes that
are not available within the project, and it will specifically flag
import statements that refer to such classes, to be sure. In that case,
however, it has the source files to work with. You may also find, if
you dig deeper, that many of the diagnostics that Eclipse provides it
obtains by compiling project sources with a compiler that issues verbose
and prolific diagnostics.
John Bollinger
jobollin@indiana.edu
- Next message: Bent C Dalager: "Re: load virtual machine once in windows ?"
- Previous message: Simon Brooke: "Repacking jar files..."
- In reply to: MB: "programmatic way for detecting imports...."
- Next in thread: Neal Gafter: "Re: programmatic way for detecting imports...."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|