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?
请先登录再写评论。
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?
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.