0

I have downloaded the aspectJ.jar file and extracted it into a temp directory (this jar file is used for test purposes only). I have the following code:

public class TestUrlClassLoader { public static void main(String [] args) throws MalformedURLException, ClassNotFoundException { File file = new File("C:\\temp\\org\\aspectj\\lang\\JoinPoint.class"); URLClassLoader loader = URLClassLoader.newInstance(new URL[]{file.toURI().toURL()}); Class<?> aClass = loader.loadClass("org.aspectj.lang.JoinPoint"); System.out.println(aClass.toString()); } } 

A file with JoinPoint class exists, but I get a ClassNotFoundException. Can anybody help me?

1 Answer 1

1

According to the javadoc of URLClassLoader,

[...] (URLClassLoader) is used to load classes and resources from a search path of URLs referring to both JAR files and directories. Any URL that ends with a '/' is assumed to refer to a directory. Otherwise, the URL is assumed to refer to a JAR file which will be opened as needed. 

You should remove the full path to the JoinPoint.class and try with the directory you want to add to the classpath, e.g.

File file = new File("C:\\temp"); URLClassLoader loader = URLClassLoader.newInstance(new URL[]{file.toURI().toURL()}); 

Reference to the javadoc: http://docs.oracle.com/javase/7/docs/api/java/net/URLClassLoader.html

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.