使用JET 生成代码中,jet模板导入 import 自定义类出现找不到该类的解决办法

今天在学习使用jet模板生成代码的时候,总是出现生成的代码为空的问题,找到的原因是:模板生成中间的java代码编译运行出错,找不到自定义的类,后来看了jet_tutorial 2教程才找到答案,解决的英文如下:

3. Classpath Issues

JETEmitter translates your templates to Java source files in the .JETEmitters project, and invokes the JavaBuilder to compile these source files. If your templates use classes that are not standard Java classes, or not in the EMF plug-in, you will need to add these classes to the classpath of the.JETEmitters project, or the JavaBuilder cannot compile the template implementation source files. Fortunately, JETEmitter provides a simple way to do this through the method addVariable which adds a Classpath Variable to the .JETEmiter project.

Classpath Variable is a workspace-wide name that is used in Eclipse to refer to a jar file or directory. The list of all such variables can be seen using the Window > Preferences > Java > Classpath Variables menua action.. Your program will need to add a classpath variable for each jar file or directory that is needed on the classpath of the .JETEmiter project.

大概的意思就是如何在模板中使用非标准的java类,在生成代码前设置addVariable 属性解决问题了

例子:

View Code
1 emitter.addVariable("com_gdie_codeGenerate", Activator.PLUGIN_ID);
2 result = emitter.generate(progress, new Object[] { typesafeEnum });

addVariable 的第一个参数变量名称,第二个参数是自定义插件的ID.

 

 

参考引用:http://www.eclipse.org/articles/Article-JET2/jet_tutorial2.html

posted on 2012-04-23 18:20  ekisstherain  阅读(465)  评论(0编辑  收藏  举报