且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

eclipse导入项目使用命令行

更新时间:2022-12-28 13:09:17

可能的方法来自Ant + Groovy:
首先创建一个包含以下内容的build.xml文件:

A possible approach would be from Ant+Groovy: First create a build.xml file with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<project name="project" default="default">  
<taskdef name="groovy"
         classname="org.codehaus.groovy.ant.Groovy"
         classpath="/home/me/workspace/Groovy/lib/groovy-all-2.1.4.jar" />  
<target name="default">
    <groovy>
        bundle = org.eclipse.core.runtime.Platform.getBundle("org.eclipse.core.resources");
        resPlugin = bundle.loadClass("org.eclipse.core.resources.ResourcesPlugin");
        root =  resPlugin.getWorkspace().getRoot();
        project = root.getProject("new");
        project.create(null);
        project.open(null);
        resPlugin.getWorkspace().save(true, null);
    </groovy>
</target>
    </project>

然后运行执行:

./eclipse -nosplash -data /home/me/workspace -application org.eclipse.ant.core.antRunner -buildfile /home/me/build.xml 

当然,一个完整的脚本将包含一些更多的代码,也许运行使用 IWorkspaceRunnable 等等,但基础在这里。只需确保您要从Eclipse使用的任何类都使用Platform.getBundle + bundle.loadClass机制定位。

Of course, a full-fledged script will contain some more code, perhaps run using an IWorkspaceRunnable and so on but the basics is here. Just be sure that any classes that you want to use from Eclipse are located using the Platform.getBundle + bundle.loadClass mechanism.