问题
I am using the following code in JvmModelInferrer.xtend to generate a Java class
@Inject extension JvmTypesBuilder
def dispatch void infer(Model element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
acceptor.accept(element.toClass(element.name)) [
annotations += annotationRef(Inject);
]
}
When I try to run the whole project, I get the following error.
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)
I tried adding the corresponding dependency com.google.inject.source;bundle-version="3.0.0"
to plugin.xml. Still I am getting the same error. How can we solve this issue?
回答1:
You have to make sure that Guice is on the classpath of the project, that contains your DSL file.
来源:https://stackoverflow.com/questions/34121018/xtext-the-type-com-google-inject-inject-is-not-on-the-classpath