File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loading Java class files

 
Priyatham Anisetty
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI ,

I want to get all the classes names which are located there and get information from class files.

I used Reflection to get all the fields information which is like this

However the above code is giving me correct result for the given exampleA.class . But I have some class files located under Users/ramu/NetBeansProjects/Ext/build/classes/poly/
1) I want to get all .class file names under specified directory
2)I want to pass class file location to getFieldsNames() so that I can reuse the same code to get information of all classes(Just by changing the parameter).

Any suggestions please
Thanks in advance

 
Pat Farrell
Rancher
Posts: 4660
5
Linux Mac OS X VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you want the Java classes loaded? or just the files in the directory tree?

You can write (without too much work) a recursive tree walker for a directory, there is even one in my Java library on the web.
 
Priyatham Anisetty
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pat Farrell wrote:Do you want the Java classes loaded? or just the files in the directory tree?

You can write (without too much work) a recursive tree walker for a directory, there is even one in my Java library on the web.


All I want is to get the declared field names in every class .
 
Pat Farrell
Rancher
Posts: 4660
5
Linux Mac OS X VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, you have to be more specific. What classes do you mean? Those loaded from your jar file? on the disk? In the whole JVM?
There are probably more types, but I can't remember them all right now.
 
Priyatham Anisetty
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pat Farrell wrote:Again, you have to be more specific. What classes do you mean? Those loaded from your jar file? on the disk? In the whole JVM?
There are probably more types, but I can't remember them all right now.


I mean the ones which are in my disk .
I have two packages in my project named "packageA" and "packageB" . This is a GUI application . When the user launches the application he will create a .java file and save it in a specified directory. Then user will compile the classes with in the gui and saves the .class file in a directory such as Ext/build/classes/poly/.

In "PackageB" , I need to load that .class file and get the information(just Declared filed names) form that .class file .

I tried this


I am getting an error
 
Pat Farrell
Rancher
Posts: 4660
5
Linux Mac OS X VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Priyatham Anisetty wrote:I mean the ones which are in my disk .


Then I would skip the whole topic of the class loader, and classes that are in memory, and simply use the standard
Java functions to read the directory and get a list of the files. Filter to suit and you are done.

File and its listFiles() method are 99% of what you need.

You could use my DirWalker class from my open source Java library. http://www.pfarrell.com/java/pdflib.tar.gz
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic