简体   繁体   English

从主要方法创建Eclipse项目

[英]Creating eclipse project from main method

Is there anyway to create temporary eclipse project and workspace from simple Java main method? 无论如何,是否可以通过简单的Java main方法创建临时的eclipse项目和工作区? I have the following code for now: 我现在有以下代码:

public static void main(String[] args)
{
    try
    {
        IProgressMonitor progress = new NullProgressMonitor();
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IWorkspaceRoot root = workspace.getRoot();

        IProject project = root.getProject();

        IProjectDescription desc = workspace.newProjectDescription(project.getName());
        IPath path = new Path("./project/");
        desc.setLocation(path);

        project.create(desc, progress);
        project.open(progress);
    }
    catch (Exception e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

But this fails to exception "Workspace is closed". 但这无法排除“工作区已关闭”的例外。 I know there must be some kind of initialization of the workspace using org.eclipse.equinox.launcher.Main but how is this done programatically? 我知道必须使用org.eclipse.equinox.launcher.Main对工作空间进行某种初始化,但是如何以编程方式完成呢? Tried to find solutions but after an hour of googling I couldn't find any. 试图找到解决方案,但经过一个小时的搜寻后,我找不到任何解决方案。

Thanks! 谢谢!

Yes and no, depending on the perspective. 是和否,取决于角度。

Calling just API will not work, as the newly launched VM did not execute all the startup functions of necessary plugins, even if you have added them to the classpath, hence fe all the paths were missing. 仅调用API是行不通的,因为新启动的VM无法执行必要插件的所有启动功能,即使您已将它们添加到classpath中,也因此缺少所有路径。

You have two options to try to solve that: 您有两种选择来尝试解决该问题:

  1. Create a full-blown RCP application . 创建功能完善的RCP应用程序
  2. Try to run your app in the same VM as Eclipse (I'm not sure if there is such a toggle in the Run... configuration). 尝试在与Eclipse相同的VM中运行您的应用程序(我不确定“运行...”配置中是否存在这样的切换)。
  3. Probably most recommended - create your own plugin with an action that will do what you want and install it in your Eclipse. 可能最推荐的做法是- 通过执行所需操作的操作创建自己的插件,然后将其安装在Eclipse中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM