473,323 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Dynamic class loading

I need to be able to select a class when my app is running, then load it
and create an instance. I know this means I need some sort of class
loader but I'm getting lost.

Classes to be loaded can be anywhere in the directory tree but the classes
(usually) don't belong to a package. If they are in the same directory
that I start the app from, things work, otherwise they don't.

Any ideas, help or refs?

Tony
Jul 17 '05 #1
2 3339
"Tony Burrows" <to**@tonyburrows.com> wrote in message
news:pa****************************@tonyburrows.co m...
| I need to be able to select a class when my app is running, then load it
| and create an instance. I know this means I need some sort of class
| loader but I'm getting lost.
|
| Classes to be loaded can be anywhere in the directory tree but the classes
| (usually) don't belong to a package. If they are in the same directory
| that I start the app from, things work, otherwise they don't.
|
| Any ideas, help or refs?
|
| Tony

Class myClass = Class.forName("com.mypackage.MyClass");
MyType instance = (MyType) myClass.newInstance();

--
-P
"Much as some folks hate to lose their way, me, I pray to God that I will."

Jul 17 '05 #2
You are correct in your assumption of needing to make a classloader.
This isn't as difficult as it sounds, and the API documentation at
http://java.sun.com/j2se/1.4.2/docs/api/ for the ClassLoader class it
very thorough in explaining how to implement one (I had to do this
myself a few months back).

Note that as far as I've been able to determine, this does NOT allow you
to load DLL files not within the OS's classpath (so JNI's are pretty
much out).

Tony Burrows wrote:
I need to be able to select a class when my app is running, then load it
and create an instance. I know this means I need some sort of class
loader but I'm getting lost.

Classes to be loaded can be anywhere in the directory tree but the classes
(usually) don't belong to a package. If they are in the same directory
that I start the app from, things work, otherwise they don't.

Any ideas, help or refs?

Tony

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Parag Joshi | last post by:
hi, I am facing a wierd problem with dyanamic class loading. I have a namespace called ETS.DAO which contains my Data Access Object classes. All these classes implement a common interface which...
17
by: Aguilar, James | last post by:
My previous example used the concept of a Shape class heirarchy, so I will continue with that. Suppose I have something like fifty different shapes, and I am trying to instantiate one of them. ...
9
by: Ender | last post by:
I have an application that I would like third party developers to be able to create Plug-ins that will be dynamically loaded into our application to extend functionality. I have utilized the...
4
by: Yan Wang | last post by:
Hi!: I encounter this problem when I do some tests: I have one user control with datalist in it. The ID for datalist is "dlTest". Then in this control code behind class, I declare a protected...
1
by: Robert McLay | last post by:
I have been trying to build python on Cray X1. As far as I can tell it does not support dynamic loading. So the question is: How to build 2.4 without dynamic loading? That is: can I build...
0
by: John Allman | last post by:
Hi all, I'm trying to create a setup which allows a program to request an object using strings and get an object of that type. It appears to be mostly working but i have difficulties if i...
13
by: jerryau | last post by:
Hi, I am trying to dynamically create object instances based on a string class name, and then I need to dynamically set values to these objects, but I have no idea how to do this in C#. Here is...
9
by: pbd22 | last post by:
Hi. This is just a disaster management question. I am using XMLHTTP for the dynamic loading of content in a very crucial area of my web site. Same as an IFrame, but using XMLHTTP and a DIV. I...
11
by: digz | last post by:
Hello, Apologies if this is the wrong group for this question. I want to design an interface , where for a custom functionality , the client writes a new class with the function implementation...
5
by: bearophileHUGS | last post by:
I often use Python to write small programs, in the range of 50-500 lines of code. For example to process some bioinformatics data, perform some data munging, to apply a randomized optimization...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.