Eclipse下如何獲得一個外掛程式的安裝目錄 getBundle

來源:互聯網
上載者:User

實際上獲得外掛程式的“安裝目錄”這樣的說法有點不對,因為Eclipse下的外掛程式全部都安裝在Plugins下面。

但是,多數人只要一想到要找一個外掛程式的位置,那就會搜尋“Eclipse 外掛程式 目錄”,所以題目我也就這麼寫了。

作為一個菜鳥,如果我要用一個之前沒有試過的東西我一般都會先建立一個很小的工程測試這個方法是事正確。

所以我就在Eclipse下面建立了一個Java工程(注意,這是禍根,後面你會明白)。


然後加了一個具有main方法的java檔案,並把

org.eclipse.core.runtime(Platform的方法都在這裡面)

org.eclipse.equinox.common(org.eclipse.core.runtime.IStatus在這裡面)

org.eclipse.osgi

等JAR引進來

然後使用

Bundle bundle = Platform.getBundle("com.core.runtime");if(bundle != null)System.out.println(bundle.toString());else System.out.println("return null!");

這段代碼來獲得外掛程式的目錄,結果死活都是null。

找啊找的,後來找到eclipse的論壇上去了,上面居然有一個和我一樣問題的人,然後才明白了。

要讓這個Platform.getBundle起作用,osgi這個架構一定要運行起來。p這是原地址:點擊開啟連結


當然了,外掛程式的作用是擴充Eclipse平台,如果你是一個Java程式(不是Eclipse外掛程式),就應該沒有“外掛程式”這一類的資源可言了吧,都已經編譯成了class的了。

意思就是Platform.getBundle這個方法只能在外掛程式開發中使用,而我一開始時建立的是Java工程,所以一直得到null。

初級看法,有誤請修正。

On 01/13/2011 09:57 AM, Tom Brandenburg wrote:> And is there a way to access resources in a plugin with a workspace> project and execution as a Java application?I'm not sure what you mean. Resources (as appropriate) can still be kept with classes and loaded via the standard java loading mechanism, like getClass().getResourceAsStream(*).Running as a "java app" means running a bunch of jars. SWT and JFace can be run as a bunch of java apps (OSGI bundles are valid java jars), but thing that depend on core.runtime and Platform cannot exist without running the OSGi framework.What exactly are you trying to do (or how did you get in this scenario)? If you are writing a plugin, simply use the OSGi Bundle.getEntry(*) mechanism. Why do you think you need to run your bundle as a java app?PW



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.