- 追加された行はこの色です。
- 削除された行はこの色です。
// 下階層用テンプレート
#topicpath
----
#contents
//ここにコンテンツを記述します。
自作のプラグインなどに設定ファイルなどがあり、そのディレクトリへのパスを取得したい場合などが結構あります。たとえばLog4jの初期化のためにlog4j.xmlを読み込む、などですね。
そこで、あるプラグインのディレクトリへのパスを取得する方法です。Eclipse2.x系から3.1系、また3.2系といろいろやり方が変わっています。
***プラグインのディレクトリを取得する(2.0系) [#ad61bd41]
String pluginDirectory = Platform
.resolve(getDefault().getDescriptor().getInstallURL()).getPath();
で取得できます。
ちなみにLog4jの初期化などはAbstractUIPluginのサブクラス(勝手に作られるヤツ)で
public void startup() throws CoreException {
super.startup();
String pluginDirectory = null;
try {
pluginDirectory =
Platform
.resolve(getDefault().getDescriptor().getInstallURL())
.getPath();
} catch (IOException e) {
e.printStackTrace();
}
DOMConfigurator.configure(new File(pluginDirectory, "lib/log4j.xml").toString());
}
などとstartup()をOverrideすればよいでしょうか。
***プラグインのディレクトリを取得する(3.0系) [#j03fe76f]
Eclipse3.0から上のやり方は deprecated になりました。2.0で
String pluginDirectory = Platform
.resolve(getDefault().getDescriptor().getInstallURL()).getPath();
だったのを3.0では
URL entry = getDefault().getBundle().getEntry("/");
String pluginDirectory = Platform.resolve(entry).getPath();
と書き換えます。
http://www3.vis.ne.jp/~asaki/p_diary/diary.cgi?Date=2004-09-05
***プラグインのディレクトリを取得する(3.2系) [#p2aca875]
Eclipse3.2からまたdeprecatedになっちゃいました。今度は、
URL entry = ClientPlugin.getDefault().getBundle().getEntry("/");
String pluginDirectory = FileLocator.resolve(entry).getPath();
みたいですね。FileLocatorは org.eclipse.core.runtime.FileLocator みたいです。
----
この記事は
#vote(おもしろかった[1],そうでもない[0])
#vote(おもしろかった[17],そうでもない[1])
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}