How to extend a loaded class or interface ?

Joined
May 19, 2009
Messages
1
Reaction score
0
Hi, I'm having a lot of trouble with this program. I know how to load classes from a URL and use their methods, but I can't extend them (or implement them if we speak about interfaces). Any ideas if it is possible ?

What I want to do is to write a class that implements the interface I've loaded from the URL.

Below is the source code. The URL has "http" in my code, not "h t t p": but the forum wouldn't let my post it because it is a link.

I packed myInterface.class in a JAR file (myPackage.JAR) and load it from there.

myInterface.java

package myPackage;

public interface myInterface {
void doSomething();​
}

testClass.java

package test;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;

public class testClass {
public static void main(String []args) throws ClassNotFoundException{
try {
URL[] urlVector = {new URL("h t t p://localhost:8080/application/myPackage.jar")};
URLClassLoader loader = new URLClassLoader(urlVector);
loader.loadClass("myPackage.myInterface");​
} catch (MalformedURLException ex) {
ex.printStackTrace();​
}​
}​
}
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top