• Post Reply Bookmark Topic Watch Topic
  • New Topic

Loading a class file in memory using java  RSS feed

 
Amol Parikh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a .class file stored in C:\Users\java. How do I load it into memory so that I can use the reflection API on them?
 
Ken Rimple
author
Ranch Hand
Posts: 63
Mac OS X Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should ad the root package directory of that class to the classpath when booting - check the -classpath command line option. Then the class can be instantiated, viewed with reflection, etc.
 
Amol Parikh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Netbeans. Does this method apply to it as well.

Thanks
 
Ken Rimple
author
Ranch Hand
Posts: 63
Mac OS X Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amol Parikh wrote:I am using Netbeans. Does this method apply to it as well.


Using Netbeans with Spring? Spring is tool and platform agnostic, it doesn't care. However, your reply seems to tell me that you want to experiment with reflection in standard Java.

If that's what you want, you can find samples in the Java Tutorial here:

http://docs.oracle.com/javase/tutorial/reflect/class/classNew.html

The whole section on reflection is really good.

Spring doesn't really make you do reflective calls-it does that for you, you give it instructions such as:



This assumes you have classes such as:



In other words, Spring, on startup, will instantiate Baz and Game, and set the game instance with the instance of Baz that it creates. That's using reflection behind the scenes.
Ken
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't a Spring question and will be moved.

Mark
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!