我在JvmModelInferrer.xtend中使用以下代码来生成Java类
@Inject extension JvmTypesBuilder
def dispatch void infer(Model element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
acceptor.accept(element.toClass(element.name)) [
annotations += annotationRef(Inject);
]
}
当我尝试运行整个项目时,出现以下错误。
5226 [main] ERROR org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder - Error initializing JvmElement
java.lang.IllegalArgumentException: The type com.google.inject.Inject is not on the classpath.
at org.eclipse.xtext.xbase.jvmmodel.JvmAnnotationReferenceBuilder.annotationRef(JvmAnnotationReferenceBuilder.java:83)
at org.eclipse.xtext.xbase.jvmmodel.JvmAnnotationReferenceBuilder.annotationRef(JvmAnnotationReferenceBuilder.java:60)
at org.example.statemodel.jvmmodel.StatemodelJvmModelInferrer.lambda$5(StatemodelJvmModelInferrer.java:60)
at org.example.statemodel.jvmmodel.StatemodelJvmModelInferrer$$Lambda$8/864303682.apply(Unknown Source)
at org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.initializeSafely(JvmTypesBuilder.java:206)
at org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder.toField(JvmTypesBuilder.java:588)
我尝试将相应的依赖项
com.google.inject.source;bundle-version="3.0.0"
添加到plugin.xml。我仍然遇到相同的错误。我们如何解决这个问题? 最佳答案
您必须确保Guice位于包含DSL文件的项目的类路径中。