﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-超越自我-文章分类-Eclipse接口</title><link>http://www.blogjava.net/jame-liu/category/3920.html</link><description>一切皆有可能</description><language>zh-cn</language><lastBuildDate>Tue, 27 Feb 2007 12:59:27 GMT</lastBuildDate><pubDate>Tue, 27 Feb 2007 12:59:27 GMT</pubDate><ttl>60</ttl><item><title>Eclipse 文件资源路径</title><link>http://www.blogjava.net/jame-liu/articles/61730.html</link><dc:creator>jame</dc:creator><author>jame</author><pubDate>Fri, 04 Aug 2006 05:57:00 GMT</pubDate><guid>http://www.blogjava.net/jame-liu/articles/61730.html</guid><wfw:comment>http://www.blogjava.net/jame-liu/comments/61730.html</wfw:comment><comments>http://www.blogjava.net/jame-liu/articles/61730.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jame-liu/comments/commentRss/61730.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jame-liu/services/trackbacks/61730.html</trackback:ping><description><![CDATA[
		<p>运行环境(runtime-workspace)下面.metadata\.plugins\xxxxxx (plugin ID)<br />AaaaPlugin.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath());</p>
		<p>
				<br />String path = ((IFile)o).getLocation().makeAbsolute().toFile().getAbsolutePath();</p>
		<p> </p>
		<p>运行环境(runtime-workspace)：</p>
		<p>IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();</p>
		<p>
				<br />从根来查找资源：</p>
		<p>IResource resource = root.findMember(new Path(containerName));</p>
		<p>IWorkspaceRoot<br /> -IProject<br />   -IFolder<br />     -IFile</p>
		<p>IResource<br />得到绝对路径方法：<br />getLocation().toOSString()<br />得到相对路径方法：<br />getFullPath().toOSString()<br />通过相对路径找到文件:<br />比如说：XXXProject下面有 "/webApp/StarflowFormEdit.jsp"<br />String path=pjt.getFile("/webApp/StarflowFormEdit.jsp").getLocation().toOSString();</p>
		<p>//Project <br />从Bundle来查找资源：</p>
		<p>Bundle bundle = Platform.getBundle(pluginId);<br />URL fullPathString = BundleUtility.find(bundle, filePath);<br />备注：<br />一个OSGI模块最重要的就是Bundle和Service，我们可以认为Bundle是一种插件管理器，<br />主要是通过BundleActivator管理模块的生命周期，而Service则是这个模块可暴露对外的服务对象。<br />这里体现了OSGI和传统的Plug-in Framework不同的一个地方，管理和静态结构分开，<br />每个Bundle拥有自己的ClassLoader以及context，通过context可进行服务的注册、卸载等，<br />这些操作都会通过事件机制广播给相应的其他的Bundle；一般来说都为通过在Bundle中编写初始需要注册的服务的方法来<br />完成Bundle可供外部使用的服务的暴露功能。</p>
		<p>
				<br />得到Appliaction workspace：<br />Platform.asLocalURL(PRODUCT_BUNDLE.getEntry("")).getPath()).getAbsolutePath();</p>
		<p>运行环境(runtime-workspace)：<br />Platform.getInstanceLocation().getURL().getPath();</p>
		<p>从编辑器来获得编辑文件：</p>
		<p>IEditorPart editor = ((DefaultEditDomain)(parent.getViewer().getEditDomain())).getEditorPart();<br />IEditorInput input = editor.getEditorInput();<br />if(input instanceof IFileEditorInput){<br />IFile file = ((IFileEditorInput)input).getFile();<br /></p>
<img src ="http://www.blogjava.net/jame-liu/aggbug/61730.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jame-liu/" target="_blank">jame</a> 2006-08-04 13:57 <a href="http://www.blogjava.net/jame-liu/articles/61730.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>