如果你想利用 JDT,你必须启动 eclipse。您可以使用扩展点“org.eclipse.core.runtime.applications”来创建从命令行启动的最小应用程序。
- 创建一个新的插件项目。
- 将“org.eclipse.core.runtime”和“org.eclipse.core.resources”添加到依赖项中。
- 为“org.eclipse.core.runtime.applications”创建一个扩展。
- 创建一个实现“org.eclipse.equinox.app.IApplication”的类并在您的扩展中引用它。
我的 plugin.xml 看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
id="id2"
point="org.eclipse.core.runtime.applications">
<application
cardinality="singleton-global"
thread="main"
visible="true">
<run class="testapplication.Application1">
</run>
</application>
</extension>
</plugin>
清单.MF:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: TestApplication
Bundle-SymbolicName: TestApplication;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: testapplication.Activator
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
应用程序1.java:
package testapplication;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
public class Application1 implements IApplication {
@Override
public Object start(IApplicationContext context) throws Exception {
System.out.println("Hello eclipse at "
+ ResourcesPlugin.getWorkspace().getRoot().getRawLocation());
return IApplication.EXIT_OK;
}
@Override
public void stop() {
// nothing to do at the moment
}
}
输出是:
你好 eclipse 在 D:/Arne/workspaces/runtime-TestApplication.id2