Project classpath?

My plugin needs to be able to load a class from the project classes or dependencies. I found the post here which explains how to get list of modules libraries using lib.getUrls(OrderRootType.CLASSES) method. The problem is that when I'm trying to create a URL object out of those Url strings, I'm getting java.net.MalformedURLException. The URL string looks like: 

jar:///Users/me/.m2/repository/com/foo/bar/1.0/bar-1.0.jar!/

and the exception is:

java.net.MalformedURLException: invalid url: ///Users/me/.m2/repository/com/foo/bar/1.0/bar-1.0.jar!/ (java.net.MalformedURLException: no protocol: ///Users/me/.m2/repository/com/foo/bar/1.0/bar-1.0.jar)

I'm not sure if I should be using a different class to instantiate the URL or is there any better way to instantiate a class loader for the project class path?

 

0
2 comments
Avatar
Permanently deleted user

Anyone? Generally speaking, what I'm trying to do is to create a class loader which can load any class from the project classes and dependencies. Is there any proper way to do that? 

0

Hello Eugene,

lib.getUrls method return URLs in IDEA's Virtual File System format. If you want to convert it to java.net.URL use com.intellij.openapi.vfs.VfsUtilCore#convertToURL method.

0

Please sign in to leave a comment.