Java プログラムメモ


トップ

Eclipse Plugin から Console(コンソール) に出力

Plugin から Console(コンソール) に出力したい場合、別の Java プロセスを実行しなければなりません。 実行すると、Debug View に実行したプラグイン名が表示され、標準出力が Console に出力されるようになります。 Java プロセスを view から実行する手順の例を下に書きます。(太字は各 Plugin で可変となる箇所です。)

※Eclipse 3.0 では Warning が出てしまいます。

ソース記述例

ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager(); ILaunchConfigurationType type = manager .getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION); ILaunchConfiguration[] config = manager.getLaunchConfigurations(type); for (int i = 0; i < config.length; i++) { if (config[i].getName().equals("プラグイン名")) { config[i].delete(); } } IPath systemLibs = new Path(JavaRuntime.JRE_CONTAINER); IRuntimeClasspathEntry systemLibsEntry = JavaRuntime .newRuntimeContainerClasspathEntry(systemLibs, IRuntimeClasspathEntry.STANDARD_CLASSES); systemLibsEntry .setClasspathProperty(IRuntimeClasspathEntry.BOOTSTRAP_CLASSES); IPluginDescriptor plugin = Platform .getPluginRegistry() .getPluginDescriptor("プラグイン ID"); ILibrary[] libs = plugin.getRuntimeLibraries(); URL pluginJar = null; try { pluginJar = Platform.asLocalURL(new URL(plugin.getInstallURL() .toExternalForm() + libs[0].getPath())); } catch (Exception e) { e.printStackTrace(); } IRuntimeClasspathEntry pluginEntry = JavaRuntime .newArchiveRuntimeClasspathEntry(new Path(pluginJar.getPath())); pluginEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES); ILaunchConfigurationWorkingCopy wc = type .newInstance(null, "プラグイン名"); List classpath = new ArrayList(); classpath.add(systemLibsEntry.getMemento()); classpath.add(pluginEntry.getMemento()); wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classpath); wc.setAttribute( IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false); wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "Java の main クラス"); wc.setAttribute( IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, "main の引数"); DebugUITools.launch(wc.doSave(), ILaunchManager.RUN_MODE);

プログラムメモ アフリカ雑貨・珈琲豆・アールブリュット作品 マゴソスクール クラウドファンディング
SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送