[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
| [pde-dev] How to load junit.jar by code? | 
Hi,i am using the following code to find junit.jar and add it to my classpath by code:
private Path findFileInPlugin(String plugin,String file)
        throws MalformedURLException,IOException
    {
       	IPluginRegistry registry=Platform.getPluginRegistry();
    	IPluginDescriptor descriptor=registry.getPluginDescriptor(plugin);
    	URL pluginURL=descriptor.getInstallURL();
    	URL jarURL=new URL(pluginURL,file);
    	System.out.println("jarURL:"+jarURL.getPath());
    	System.out.println("Protocal:"+jarURL.getProtocol());
    	URL localJarURL=Platform.asLocalURL(jarURL);//FileNotFoundException    	
    	return new Path(localJarURL.getPath());
    }
The print out is like this:
jarURL:/plugin/org.junit_3.8.1/junit.jar
Protocal:platform
it finally throws a FileNotFoundException from the like annotated with FileNotFoundException.
The stack trace is
java.io.FileNotFoundException: /junit.jar
	at org.eclipse.osgi.framework.internal.protocol.bundleentry.Handler.findBundleEntry(Handler.java:42)
	at org.eclipse.osgi.framework.internal.core.BundleResourceHandler.openConnection(BundleResourceHandler.java:155)
	at java.net.URL.openConnection(URL.java:943)
	at org.eclipse.core.runtime.internal.adaptor.URLConverterImpl.convertToFileURL(URLConverterImpl.java:29)
	at org.eclipse.core.internal.runtime.InternalPlatform.asLocalURL(InternalPlatform.java:215)
	at org.eclipse.core.runtime.Platform.asLocalURL(Platform.java:507)
	at org.eclipse.robin.junit.test.TestProject.findFileInPlugin(TestProject.java:86)
	.................................
Please Help!
Best Regards!
	需要一个2000兆的免费邮箱吗?
	
	网易免费邮箱是中国最多人使用的电子邮箱。