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 {
testClass.java
package test;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
public class testClass {
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) {URLClassLoader loader = new URLClassLoader(urlVector);
loader.loadClass("myPackage.myInterface");
ex.printStackTrace();
}
Last edited: