Eclipse 插件開發遇到問題心得總結

Eclipse 插件開發遇到問題心得總結

Posted on?2011-07-17 00:51?季楓?閱讀(3997) 評論(0)?編輯?收藏

1、Eclipse 中插件開發多語言的實現

為了使用 .properties 文件,需要在 META-INF/MANIFEST.MF 文件中定義:
????? Bundle-Localization: plugin
這樣就會自動加載 plugin.properties 文件(中文找 plugin_zh_CN.properties)
然后在 plugin.xml 文件中,將字符串替換為 %key 就可以了
建議先使用 Eclipse 的外部化字符串目錄:

Bundle-Localization:?OSGI-INF/l10n/plugin?

?

?

2、Eclipse 插件開發初始化隱藏某工具欄按鈕

在網上找了好久都找不到解決辦法,最后搜索 eclipse 安裝目錄,從它自己的插件里面找到樣例了。樣例來自 org.eclipse.jdt.ui/plugin.xml

?

復制代碼

<extension
<extension point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension? targetID="*">
<!-- 注意這里的 id 是 action 或 command 的 id -->
<hiddenToolBarItem??? id="org.eclipse.jdt.ui.actions.OpenProjectWizard">
</hiddenToolBarItem>
</perspectiveExtension>??
復制代碼

?

3、插件中獲取 Eclipse 版本號

?

01.String?sEclipseVersion?=?System.getProperty("osgi.framework.version");??

4、插件中獲取路徑

復制代碼

// 得到插件所在的路徑
Platform.asLocalURL(Platform.getBundle("your plugin ID").getEntry("")).getFile();

// 得到當前工作空間的路徑
Platform.getInstanceLocation().getURL().getFile();

// 得到當前工作空間下的所有工程
ResourcesPlugin.getWorkspace().getRoot().getProjects();

// 得到某 PLUGIN 的路徑:
Platform.getBundle("mypluginid").getLocation().
// eclipse采用osgi后好像還可以:
Activator.getDefault().getBundle().getLocation(); //前提是這個插件有Activator這個類.這個類繼承了ECLIPSE的Plugin類
// eclipse采用osgi前好像好像是:
MyPlugin.getDefault().getBundle().getLocation(); //前提是這個插件有MyPlugin這個類.這個類繼承了ECLIPSE的Plugin類

// 得到工作區路徑:
Platform.getlocation();
// 或 ResourcesPlugin.getWorkspace(); 好像 Platform.getInstanceLocation() 也可行

// 得到ECLIPSE安裝路徑
Platform.getInstallLocation();

// 從插件中獲得絕對路徑:
AaaaPlugin.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath();

// 通過文件得到 Project:
IProject project = ((IFile)o).getProject();

// 通過文件得到全路徑:
String path = ((IFile)o).getLocation().makeAbsolute().toFile().getAbsolutePath();

// 得到整個Workspace的根:
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

// 從根來查找資源:
IResource resource = root.findMember(new Path(containerName));

// 從Bundle來查找資源:
Bundle bundle = Platform.getBundle(pluginId);
URL fullPathString = BundleUtility.find(bundle, filePath);

// 得到 Appliaction workspace:
Platform.asLocalURL(PRODUCT_BUNDLE.getEntry("")).getPath()).getAbsolutePath();

// 得到 runtimeworkspace:
Platform.getInstanceLocation().getURL().getPath();

// 從編輯器來獲得編輯文件
IEditorPart editor = ((DefaultEditDomain)(parent.getViewer().getEditDomain())).getEditorPart();
IEditorInput input = editor.getEditorInput();
if(input instanceof IFileEditorInput)
{
IFile file = ((IFileEditorInput)input).getFile();
}

//?獲取插件的絕對路徑:
FileLocator.resolve(BuildUIPlugin.getDefault().getBundle().getEntry("/")).getFile();
復制代碼


?5、添加myeclipse JAVAEE Library?與User?Library

IClasspathEntry?myEclipseJAVAEE5?=JavaCore.newContainerEntry(new?Path("melibrary.com.genuitec.eclipse.j2eedt.core.MYECLIPSE_JAVAEE_5_CONTAINER"));
IClasspathEntry?myEclipseUCITPortletDev?=JavaCore.newContainerEntry(new?Path("org.eclipse.jdt.USER_LIBRARY/UCITPortletDev"));

?

6、利用Ifile向項目中寫文件

?

復制代碼
????/**
?????*?jar文件輸入流
?????*?
@param?path
?????*?
@return
?????
*/
????
private?InputStream?fileInput(File?path){
????????
????????
try?{
????????????FileInputStream?fis
=new?FileInputStream(path);
????????????
return?fis;
????????}?
catch?(FileNotFoundException?e)?{
????????????
//?TODO?Auto-generated?catch?block
????????????e.printStackTrace();
????????}
????????
return?null;
????}
????
????
/**
?????*?Adds?a?new?file?to?the?project.
?????*?
?????*?
@param?container
?????*?
@param?path
?????*?
@param?contentStream
?????*?
@param?monitor
?????*?
@throws?CoreException
?????
*/
????
private?void?addFileToProject(IContainer?container,?Path?path,
????????????InputStream?contentStream,?IProgressMonitor?monitor)
????????????
throws?CoreException?{
????????
final?IFile?file?=?container.getFile(path);

????????
if?(file.exists())?{
????????????file.setContents(contentStream,?
true,?true,?monitor);
????????}?
else?{
????????????file.create(contentStream,?
true,?monitor);
????????}

????}
復制代碼

?

復制代碼
????????//寫入自動生成portlet環境的jar包
????????IContainer?container?=?(IContainer)?project;
????????IProgressMonitor?monitor?
=?new?NullProgressMonitor();
????????Path?autoJar
=new?Path(WEBROOT+FILESEPARATOR+WEBINF+FILESEPARATOR?+LIB+FILESEPARATOR+"UcitPortletDev.jar");????//項目路徑
????????InputStream?jarIS=fileInput(new?File("d:/PortletAuto.jar"));????//本地文件路徑
????????
????????
//寫入自動生成portlet環境的xml配置文件
????????Path?autoConfigXML=new?Path("src"+FILESEPARATOR+"service_portlet.xml");????//項目路徑
????????InputStream?XMLIS=fileInput(new?File(selectConfigPath));????//本地文件路徑
????????
????????
try?{
????????????addFileToProject(container,autoJar,jarIS,monitor);????
//Jar
????????????monitor?=?new?NullProgressMonitor();
????????????addFileToProject(container,autoConfigXML,XMLIS,monitor);????
//XML
????????}?catch?(CoreException?e)?{
????????????
//?TODO?Auto-generated?catch?block
????????????e.printStackTrace();
????????}
finally{
????????????
if?(jarIS!=null){
????????????????jarIS.close();
????????????}
????????????
if?(XMLIS!=null){
????????????????XMLIS.close();?
????????????}
????????}
復制代碼

?

7、獲取Eclipse當前項目

復制代碼
public?static?IProject?getCurrentProject(){???
????????ISelectionService?selectionService?=????
????????????Workbench.getInstance().getActiveWorkbenchWindow().getSelectionService();???
???
????????ISelection?selection?=?selectionService.getSelection();???
???
????????IProject?project?=?null;???
????????if(selection?instanceof?IStructuredSelection)?{???
????????????Object?element?=?((IStructuredSelection)selection).getFirstElement();???
???
????????????if?(element?instanceof?IResource)?{???
????????????????project=?((IResource)element).getProject();???
????????????}?else?if?(element?instanceof?PackageFragmentRootContainer)?{???
????????????????IJavaProject?jProject?=????
????????????????????((PackageFragmentRootContainer)element).getJavaProject();???
????????????????project?=?jProject.getProject();???
????????????}?else?if?(element?instanceof?IJavaElement)?{???
????????????????IJavaProject?jProject=?((IJavaElement)element).getJavaProject();???
????????????????project?=?jProject.getProject();???
????????????}???
????????}????
????????return?project;???
????}???
復制代碼

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/388139.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388139.shtml
英文地址,請注明出處:http://en.pswp.cn/news/388139.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

/src/applicationContext.xml

<?xml version"1.0" encoding"UTF-8"?> <beans xmlns"http://www.springframework.org/schema/beans" xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance" xmlns:context"http://www.springframework.org/schema…

在Python中查找子字符串索引的5種方法

在Python中查找字符串中子字符串索引的5種方法 (5 Ways to Find the Index of a Substring in Strings in Python) str.find() str.find() str.rfind() str.rfind() str.index() str.index() str.rindex() str.rindex() re.search() re.search() str.find() (str.find()) …

[LeetCode] 3. Longest Substring Without Repeating Characters 題解

問題描述 輸入一個字符串&#xff0c;找到其中最長的不重復子串 例1&#xff1a; 輸入&#xff1a;"abcabcbb" 輸出&#xff1a;3 解釋&#xff1a;最長非重復子串為"abc" 復制代碼例2&#xff1a; 輸入&#xff1a;"bbbbb" 輸出&#xff1a;1 解…

WPF中MVVM模式的 Event 處理

WPF的有些UI元素有Command屬性可以直接實現綁定&#xff0c;如Button 但是很多Event的觸發如何綁定到ViewModel中的Command呢&#xff1f; 答案就是使用EventTrigger可以實現。 繼續上一篇對Slider的研究&#xff0c;在View中修改Interaction. <i:Interaction.Triggers>&…

Eclipse 插件開發 向導

閱讀目錄 最近由于特殊需要&#xff0c;開始學習插件開發。   下面就直接弄一個簡單的插件吧!   1 新建一個插件工程   2 創建自己的插件名字&#xff0c;這個名字最好特殊一點&#xff0c;一遍融合到eclipse的時候&#xff0c;不會發生沖突。   3 下一步&#xff0c;進…

線性回歸 假設_線性回歸的假設

線性回歸 假設Linear Regression is the bicycle of regression models. It’s simple yet incredibly useful. It can be used in a variety of domains. It has a nice closed formed solution, which makes model training a super-fast non-iterative process.線性回歸是回…

ES6模塊與commonJS模塊的差異

參考&#xff1a; 前端模塊化 ES6 在語言標準的層面上&#xff0c;實現了模塊功能&#xff0c;而且實現得相當簡單&#xff0c;旨在成為瀏覽器和服務器通用的模塊解決方案。 其模塊功能主要由兩個命令構成&#xff1a;export和import。export命令用于規定模塊的對外接口&#x…

solo

solo - 必應詞典 美[so?lo?]英[s??l??]n.【樂】獨奏(曲)&#xff1b;獨唱(曲)&#xff1b;單人舞&#xff1b;單獨表演adj.獨唱[奏]的&#xff1b;單獨的&#xff1b;單人的v.獨奏&#xff1b;放單飛adv.獨網絡梭羅&#xff1b;獨奏曲&#xff1b;索羅變形復數&#xff1…

Eclipse 簡介和插件開發天氣預報

Eclipse 簡介和插件開發 Eclipse 是一個很讓人著迷的開發環境&#xff0c;它提供的核心框架和可擴展的插件機制給廣大的程序員提供了無限的想象和創造空間。目前網上流傳相當豐富且全面的開發工具方面的插件&#xff0c;但是 Eclipse 已經超越了開發環境的概念&#xff0c;可以…

趣味數據故事_壞數據的好故事

趣味數據故事Meet Julia. She’s a data engineer. Julia is responsible for ensuring that your data warehouses and lakes don’t turn into data swamps, and that, generally speaking, your data pipelines are in good working order.中號 EETJulia。 她是一名數據工程…

Linux 4.1內核熱補丁成功實踐

最開始公司運維同學反饋&#xff0c;個別宿主機上存在進程CPU峰值使用率異常的現象。而數萬臺機器中只出現了幾例&#xff0c;也就是說萬分之幾的概率。監控產生的些小誤差&#xff0c;不會造成宕機等嚴重后果&#xff0c;很容易就此被忽略了。但我們考慮到這個異常轉瞬即逝、并…

python分句_Python循環中的分句,繼續和其他子句

python分句Python中的循環 (Loops in Python) for loop for循環 while loop while循環 Let’s learn how to use control statements like break, continue, and else clauses in the for loop and the while loop.讓我們學習如何在for循環和while循環中使用諸如break &#xf…

eclipse plugin 菜單

簡介&#xff1a; 菜單是各種軟件及開發平臺會提供的必備功能&#xff0c;Eclipse 也不例外&#xff0c;提供了豐富的菜單&#xff0c;包括主菜單&#xff08;Main Menu&#xff09;&#xff0c;視圖 / 編輯器菜單&#xff08;ViewPart/Editor Menu&#xff09;和上下文菜單&am…

[翻譯 EF Core in Action 2.0] 查詢數據庫

Entity Framework Core in Action Entityframework Core in action是 Jon P smith 所著的關于Entityframework Core 書籍。原版地址. 是除了官方文檔外另一個學習EF Core的不錯途徑, 書中由淺入深的講解的EF Core的相關知識。因為沒有中文版,所以本人對其進行翻譯。 預計每兩天…

hdu5692 Snacks dfs序+線段樹

題目傳送門 題目大意&#xff1a;給出一顆樹&#xff0c;根節點是0&#xff0c;有兩種操作&#xff0c;一是修改某個節點的value&#xff0c;二是查詢&#xff0c;從根節點出發&#xff0c;經過 x 節點的路徑的最大值。 思路&#xff1a;用樹狀數組寫發現還是有些麻煩&#xff…

python數據建模數據集_Python中的數據集

python數據建模數據集There are useful Python packages that allow loading publicly available datasets with just a few lines of code. In this post, we will look at 5 packages that give instant access to a range of datasets. For each package, we will look at h…

打開editor的接口討論

【打開editor的接口討論】 先來看一下workbench吧&#xff0c;workbench從靜態劃分應該大致如下&#xff1a; 從結構圖我們大致就可以猜測出來&#xff0c;workbench page作為一個IWorkbenchPart&#xff08;無論是eidtor part還是view part&#…

【三角函數】已知直角三角形的斜邊長度和一個銳角角度,求另外兩條直角邊的長度...

如圖,已知直角三角形ABC中,∠C90, ∠Aa ,ABc ,求直角邊AC、BC的長度. ∵ ∠C90,∠Aa ,ABc ,Cos∠AAC/AB ,Sin∠ABC/AB ,∴ ACAB*Cos∠Ac*Cosa ,BCAB*Sin∠Ac*Sina . 復制代碼

網絡攻防技術實驗五

2018-10-23 實驗五 學 號201521450005 中國人民公安大學 Chinese people’ public security university 網絡對抗技術 實驗報告 實驗五 綜合滲透 學生姓名 陳軍 年級 2015 區隊 五 指導教師 高見 信息技術與網絡安全學院 2018年10月23日 實驗任務總綱 2018—2019 …

usgs地震記錄如何下載_用大葉草繪制USGS地震數據

usgs地震記錄如何下載One of the many services provided by the US Geological Survey (USGS) is the monitoring and tracking of seismological events worldwide. I recently stumbled upon their earthquake datasets provided at the website below.美國地質調查局(USGS)…