リソースの取得方法

「リソースの取得方法」の編集履歴(バックアップ)一覧はこちら

リソースの取得方法」(2011/01/05 (水) 14:23:11) の最新版変更点

追加された行は緑色になります。

削除された行は赤色になります。

Eclipseの実行ファイル eclipse.exe の場所 java.io.File f = new File("eclipse.exe"); String path = f.getAbsolutePath() ワークスペースの場所 ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString() プラグイン内のリソース try { Bundle bundle = Platform.getBundle("com.xxx");//プラグインID URL bundleUrl = bundle.getResource("icons");//プラグインからのリソースパス URL fileUrl = org.eclipse.core.runtime.FileLocator.toFileURL(bundleUrl);//変換 bundlePath = fileUrl.toString(); //getPath()でも可 pluginEntryPath = fileUrl.getPath(); // なぜか先頭は'/'となる // path = /C:/・・・eclipse/workspace/com.xxx/ if (pluginEntryPath.charAt(0) == '/') { pluginEntryPath = pluginEntryPath.substring(1); } } catch (IOException e) { } プロジェクト一覧 ResourcesPlugin.getWorkspace().getRoot().getProjects() リソース変換 IFile to File IFile f = ...; IPath location = f.getLocation(); if (location != null) java.io.File file = location.toFile() org.eclipse.core.runtime.IPath → org.eclipse.emf.common.util.URI IPath path = delta.getMovedFromPath(); URI uri = URI.createPlatformResourceURI(path.toString(), true); org.eclipse.core.resources.IFile → org.eclipse.emf.common.util.URI IFile file = ...; URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true); org.eclipse.core.resources.IFile → org.eclipse.emf.ecore.resource.Resource String path = ((IFile)parentElement).getFullPath().toString(); URI uri = URI.createPlatformResourceURI(path, true); TransactionalEditingDomain editingDomain = EditingDomainManager.getEditingDomain(file); ResourceSet resourceSet = editingDomain.getResourceSet(); Resource resource = resourceSet.getResource(uri, true); org.eclipse.emf.ecore.resource.Resource → org.eclipse.core.resources.IFile org.eclipse.emf.ecore.resource.Resource r = ...; IFile file = org.eclipse.emf.workspace.util.WorkspaceSynchronizer.getFile(r) EObject eobj = (EObject) selected; Resource r = eobj.eResource(); String strFile = r.getURI().toPlatformString(false); IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(strFile));
Eclipseの実行ファイル eclipse.exe の場所 java.io.File f = new File("eclipse.exe"); String path = f.getAbsolutePath() ワークスペースの場所 ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString() プラグイン内のリソース try { Bundle bundle = Platform.getBundle("com.xxx");//プラグインID URL bundleUrl = bundle.getResource("icons");//プラグインからのリソースパス URL fileUrl = org.eclipse.core.runtime.FileLocator.toFileURL(bundleUrl);//変換 bundlePath = fileUrl.toString(); //getPath()でも可 pluginEntryPath = fileUrl.getPath(); // なぜか先頭は'/'となる // path = /C:/・・・eclipse/workspace/com.xxx/ if (pluginEntryPath.charAt(0) == '/') { pluginEntryPath = pluginEntryPath.substring(1); } } catch (IOException e) { } プロジェクト一覧 ResourcesPlugin.getWorkspace().getRoot().getProjects() リソース変換 IFile to File IFile f = ...; IPath location = f.getLocation(); if (location != null) java.io.File file = location.toFile() org.eclipse.core.runtime.IPath → org.eclipse.emf.common.util.URI IPath path = delta.getMovedFromPath(); URI uri = URI.createPlatformResourceURI(path.toString(), true); org.eclipse.core.resources.IFile → org.eclipse.emf.common.util.URI IFile file = ...; URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true); org.eclipse.core.resources.IFile → org.eclipse.emf.ecore.resource.Resource String path = ((IFile)parentElement).getFullPath().toString(); URI uri = URI.createPlatformResourceURI(path, true); TransactionalEditingDomain editingDomain = EditingDomainManager.getEditingDomain(file); ResourceSet resourceSet = editingDomain.getResourceSet(); Resource resource = resourceSet.getResource(uri, true); org.eclipse.emf.ecore.resource.Resource → org.eclipse.core.resources.IFile org.eclipse.emf.ecore.resource.Resource r = ...; IFile file = org.eclipse.emf.workspace.util.WorkspaceSynchronizer.getFile(r) EObject eobj = (EObject) selected; Resource r = eobj.eResource(); String strFile = r.getURI().toPlatformString(false); IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(strFile)); //プラグイン内のプロパティファイルの取得方法 Bundle bundle = Platform.getBundle("xxx.yyy.zzz.plugin"); URL propURL = FileLocator.toFileURL(bundle.getEntry("/resource/message.properties")); File file = new File(propURL.getFile()); Properties properties = new Properties(); properties.load(new FileInputStream(file));

表示オプション

横に並べて表示:
変化行の前後のみ表示:
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。