当前位置: 首页 > 工具软件 > Acceleo > 使用案例 >

Acceleo_新建与运行

谷梁淇
2023-12-01

1 File->New->Acceleo project(填写项目名称,其它默认);

2 Next->选择Metamodel URIs(需要现在的工作空间中包含元模型)->在添加时选择Runtime Version->选中Generate documentation/Generate file/Main template->finish

3 编写*.mtl文件

4 运行报错:

Exception in thread "main" org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'http://www.example.org/uilm' not found. (file:/E:/eclipseworkspace/Acceleo/org.eclipse.acceleo.module.sample/Trans/inModel.xmi, 8, 18)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:319)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:278)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
at org.eclipse.acceleo.common.utils.ModelUtils.load(ModelUtils.java:391)
at org.eclipse.acceleo.common.utils.ModelUtils.load(ModelUtils.java:356)
at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.initialize(AbstractAcceleoGenerator.java:488)
at org.eclipse.acceleo.module.sample.main.Generate.<init>(Generate.java:90)

at org.eclipse.acceleo.module.sample.main.Generate.main(Generate.java:144)

原因:在本项目中没有包含uilm.ecore元模型

解决办法:New->Folder->将uilm.ecore拷贝到该文件夹中

5 运行出错:

The generation failed to generate any file because there are no model elements that matches at least the type of the first parameter of one of your main templates. 

The problem may be caused by a problem with the registration of your metamodel, please see the method named "registerPackages" in the Java launcher of your generator. It could also come from a missing [comment @main/] 

in the template used as the entry point of the generation. 

原因:

代码中缺少[comment @main/] 

原来代码为:

[comment encoding = UTF-8 /]
[**
 * The documentation of the module generate.
 */]
[module generate('http://www.example.org/uilm')]
[**
 * The documentation of the template generateElement.
 * @param aDirection
 */]

[template public generateElement(aWinApplication : WinApplication)]

...........................................后面是具体转换

修改后代码为:

[comment encoding = UTF-8 /]
[**
 * The documentation of the module generate.
 */]
[module generate('http://www.example.org/uilm')]
[**
 * The documentation of the template generateElement.
 * @param aDirection
 */]
[template public generateElement(aWinApplication : WinApplication)]

[comment @main/]

...........................................运行成功

6 运行配置:

Project:项目名称

Main class:项目名称.main.Generate

Model:输入模型(*.xml)

Target:生成文件的位置

Runner:Java Application





 类似资料: