• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Loading Java class files

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Rancher
Posts: 4804
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4804
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4804
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic