使用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

转载于:https://www.cnblogs.com/ekisstherain/articles/2466924.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值