0

I want to load a class on my local file system,so I try to use the URLClassloader to do it,and Here is my code

public void testDynamaicLoader() throws Exception {      
    String path = "D://temp";
    String repository = (new URL("file", null,
        path+File.separator)).toString();
    URL[] urls = new URL[1];
    URLStreamHandler streamHandler = null;
    urls[0] = new URL(null, repository,streamHandler);
    URLClassLoader loader = new URLClassLoader(urls);
    loader.loadClass("com.MyService");
}

The target class MyService is in the path of D:/temp/com/ and it's in the package com But when I run my test method I get the error information follows

java.lang.NoClassDefFoundError: com/MyService

I have no idea why this happened,help me please,Thanks!

Gmx
  • 155
  • 6

0 Answers0