This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Loading a Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Loading a ".class" from a specified path using a JAVA  program" Watch "Loading a ".class" from a specified path using a JAVA  program" New topic
Author

Loading a ".class" from a specified path using a JAVA program

Amol Parikh
Greenhorn

Joined: May 29, 2012
Posts: 11
I want to compile a JAVA file that i have stored at a location.After compilation a .class is created in the same directory. I would like to load this class file in the memory and fiddle around with the reflection API. Would be grateful for your inputs...
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 888
    
    9
You make sure the class is on the classpath of the program that is doing the reflection and load it using Class.forName.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
It's Java and not JAVA (not an acronym) and welcome to the Ranch, Amol.
Amol Parikh
Greenhorn

Joined: May 29, 2012
Posts: 11
It is not on the class path and would like to load it explicitly using an absolute path...!!!
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1167
The following code works for java.util.List class as well as for the Animal one -



William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 888
    
    9
Amol Parikh wrote:It is not on the class path and would like to load it explicitly using an absolute path...!!!


Then you'll need to create a class loader and define the class, see :http://www.javaworld.com/javaworld/jw-06-2006/jw-0612-dynamic.html
 
jQuery in Action, 2nd edition
 
subject: Loading a ".class" from a specified path using a JAVA program
 
Similar Threads
Extracting Image From A Jar File
How to save the decompile class file using JAD plugin in eclipse- urgent
creating a .dll from a class
creating a .dll from a class
Java File Name