是否可以创建命令行JDT应用程序? [英] Is it possible to create a command line JDT application?

查看:132
本文介绍了是否可以创建命令行JDT应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个命令行应用程序来分析Java代码。 Eclipse JDT似乎是正确的工作,但是我可以在JDT上找到的每个教程启动JDT作为Eclipse插件。

I want to create a command line application which does analysis of Java code. The Eclipse JDT seems like the right tool for the job, however every tutorial I can find on the JDT starts up the JDT as an Eclipse plugin.

我会期望这样的:

public static void main(String[] args) throws Exception {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    ...
}

但是getWorkspace()抛出一个服务未启动的异常。

to get started. However getWorkspace() throws an exception that the service is not started.

推荐答案

如果你想利用JDT, 。您可以使用扩展点org.eclipse.core.runtime.applications创建从命令行启动的最小应用程序。

If you want to leverage JDT you have to start eclipse. You can use the extension point "org.eclipse.core.runtime.applications" to create a minimal application that starts from the command line.


  1. 创建一个新的Plugin-Project。

  2. 将org.eclipse.core.runtime和org.eclipse.core.resources添加到依赖项。

  3. 创建扩展

  4. 创建一个实现org.eclipse.equinox.app.IApplication的类并在扩展中引用它。

  1. Create a new Plugin-Project.
  2. Add "org.eclipse.core.runtime" and "org.eclipse.core.resources" to the dependencies.
  3. Create an extension for "org.eclipse.core.runtime.applications".
  4. Create a class that implements "org.eclipse.equinox.app.IApplication" and reference it in your extension.

我的plugin.xml如下所示:

My plugin.xml looks like this:

<?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>

MANIFEST.MF:

MANIFEST.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

Application1.java:

Application1.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
    }

}

输出为:


您在e:/Arne/workspaces/runtime-TestApplication.id2

Hello eclipse at D:/Arne/workspaces/runtime-TestApplication.id2

这篇关于是否可以创建命令行JDT应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆