在代码中运行模型就是用代码获取模型和执行模型的方法,可以参看在Java代码中启动事物管理器。
import java.io.File; import org.xmeta.Thing; import org.xmeta.World; import org.xmeta.ActionContext; public class RunXWorkerIDE { public static void main(String[] args){ try{ //初始化引擎,初始化参数为null,会根据系统变量XMETA_HOME或XWORKER_HOME寻找xworker的安装目录 World world = World.getInstance(); world.init(null); //添加Java项目下的模型的所在目录 world.addFileThingManager("myproject", new File("./src/main/resources/"), false, true); //启动编辑器 Thing worldExplorer = World.getInstance().getThing("xworker.ide.worldExplorer.swt.SimpleExplorerRunner"); worldExplorer.doAction("run", new ActionContext()); }catch(Exception e){ e.printStackTrace(); } } }
在上面的代码里,World在系统启动时初始化一次即可,通过world.getThing(thingpath)来获取指定的事物,通过thing.doAction("xxx", new ActionContext())来执行模型的xxx方法。
Copyright © 2007-2014 XWorker.org 版权所有