[英]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: 您有两种选择来尝试解决该问题:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.