我的插件具有html文件资源,该资源正在SWT浏览器小部件上显示。
我可以使用以下代码从插件侧面的资源文件夹中找到此html文件:
public File resolveResource(URL url) {
File resolvedFile = null;
try {
URL resolvedFileURL = FileLocator.toFileURL(url);
URI resolvedURI = new URI(resolvedFileURL.getProtocol(), resolvedFileURL.getPath(), null);
resolvedFile = new File(resolvedURI);
} catch (Exception e) {
// exception handling
}
return resolvedFile;
}
现在,此html文件资源引用了一些CSS图像,这些图像存在于插件内的同一资源文件夹中。
问题是当我打包并部署插件并尝试运行它时-图像和CSS无法显示/解析。
当我从IDE运行“ Eclipse应用程序”时,此方法运行良好。
HTML文件资源:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta name="viewport" content="initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; width=device-width" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="css/styles.css" type="text/css" />
</head>
<body>
<div class="content" id="parent">
</div>
<div class="footer">
All contents copyright 2014.
</div>
</body>
</html>
FileLocator.toFileURL
期望使用由返回的格式的URL FileLocator.find
。正常用法是:
Bundle bundle = Platform.getBundle("plugin id");
URL url = FileLocator.find(bundle, new Path("plugin relative path"), null);
URL fileURL = FileLocator.toFileURL(url);
使用它很重要,FileLocator.find
因为特殊URL用于插件Jar文件中的资源。
如果需要访问文件夹中的其他文件,则应为插件使用“功能”项目,并指定在插件安装过程中解压缩插件,以便为文件创建一个普通文件夹。或使用'Eclipse-BundleShape'-有关更多详细信息,请参见此处。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句