Eclipse-将IPath转换为URL

Eclipse-将IPath转换为URL,eclipse,eclipse-plugin,eclipse-rcp,Eclipse,Eclipse Plugin,Eclipse Rcp,如何将IPath转换为URL。在我的例子中,我希望将Java项目的输出位置转换为URL,以便使用URLClassLoader从那里加载类。我的代码如下所示: javaProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null); URL url = new File( javaProject.getOutputLocation().toFile().getAbsolutePath() ).toURI().toURL

如何将IPath转换为URL。在我的例子中,我希望将Java项目的输出位置转换为URL,以便使用
URLClassLoader
从那里加载类。我的代码如下所示:

javaProject.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);

URL url = new File( javaProject.getOutputLocation().toFile().getAbsolutePath() ).toURI().toURL();
URL[] urls = new URL[] { url };
URLClassLoader classLoader = new URLClassLoader(urls);
Class<?> c = classLoader.loadClass(fully-qualified-class-name);
javaProject.getProject().build(IncrementalProjectBuilder.FULL_build,null);
URL URL=新文件(javaProject.getOutputLocation().toFile().getAbsolutePath()).toURI().toul();
URL[]URL=新URL[]{URL};
URLClassLoader=新的URLClassLoader(URL);
c类=classLoader.loadClass(完全限定类名);
问题在于URL只是一个相对的URL,即它的字符串表示形式是
file:/C:/com.florianigerl.regexfinandreplace.matchevaluators/bin
,但它应该类似于
file:/C:/Users/Hermann/runtime EclipseApplication/com.florianigerl.regexfinandreplace.matchevaluators/bin

URLClassLoader
显然找不到类


非常感谢您的帮助。

您可以使用以下方法:

IPath path=javaProject.getOutputLocation();
IFile file=ResourcesPlugin.getWorkspace().getRoot().getFile(路径);
URI=file.getLocationURI();
URL=uri.toURL();