NullPointerException reading Xtext model outside of Eclipse [message #514869] |
Tue, 16 February 2010 18:27  |
Eclipse User |
|
|
|
I want to use Xtext to read a model in a stand-alone Java application, i.e. outside of Ecplise and not using OSGi. The following code works fine if I start it inside Eclipse, but it throws a NPE when I start it outside Eclipse (the commented out code stands for variations I tried - they all yielded the identical exception).
public static EObject readModel (String filename) throws IOException {
final Injector injector = new PromptStandaloneSetup().createInjectorAndDoEMFRegistration();
// final IParser parser = injector.getInstance(IParser.class);
final ResourceSet set = injector.getInstance(XtextResourceSet.class);
final Resource res = set.getResource(URI.createURI (filename), true);
return res.getContents().get(0);
//return ModelUtils.load (filename, set);
//new StandaloneSetup();
/*
final MweReader reader = new MweReader();
reader.setUri (filename);
reader.setRegister (new prompt.PromptStandaloneSetup ());
reader.setOutputSlot ("model");
final WorkflowContextDefaultImpl context = new WorkflowContextDefaultImpl();
final IssuesImpl issues = new IssuesImpl ();
reader.invoke (context, null, issues);
// for (error <- issues.getErrors.map(_.getMessage))
// ctx.error (error)
// for (warning <- issues.getWarnings.map(_.getMessage))
// ctx.error (warning)
// if (! issues.getErrors.isEmpty)
// ctx.fail ("errors while parsing model")
return (EObject) context.get ("model");
*/
}
The stacktrace is as follows:
Exception in thread "main" java.lang.NullPointerException
at org.eclipse.xtext.parser.antlr.AntlrTokenDefProvider.getTokenDefMap(AntlrTokenDefProvider.java:64)
at org.eclipse.xtext.parser.antlr.XtextTokenStream.<init>(XtextTokenStream.java:50)
at prompt.parser.antlr.PromptParser.parse(PromptParser.java:27)
at org.eclipse.xtext.parser.antlr.AbstractAntlrParser.parse(AbstractAntlrParser.java:51)
at org.eclipse.xtext.parser.antlr.AbstractAntlrParser.doParse(AbstractAntlrParser.java:34)
at org.eclipse.xtext.parser.antlr.AbstractAntlrParser.doParse(AbstractAntlrParser.java:1)
at org.eclipse.xtext.parser.AbstractParser.parse(AbstractParser.java:27)
at org.eclipse.xtext.parser.SwitchingParser.parse(SwitchingParser.java:49)
at org.eclipse.xtext.resource.XtextResource.doLoad(XtextResource.java:151)
at org.eclipse.xtext.linking.lazy.LazyLinkingResource.doLoad(LazyLinkingResource.java:43)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1494)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1282)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:255)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:270)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:397)
at ex.Ex.readModel(Ex.java:48)
at ex.Ex.main(Ex.java:79)
I used the following classpath (using Xtext 0.8 shows the same behaviour):
export CLASSPATH=myproject/out/production/emf-read
export CLASSPATH=$CLASSPATH:myproject/lib/org.eclipse.xtext.util_0.7.2.v200908120607.jar
export CLASSPATH=$CLASSPATH:myproject/lib/org.eclipse.xtext.log4j_1.2.15.v200908120607.jar
export CLASSPATH=$CLASSPATH:myproject/lib/com.google.collect_0.8.0.v200908120607.jar
export CLASSPATH=$CLASSPATH:myproject/lib/org.eclipse.emf.ecore.xmi_2.5.0.v200906151043.jar
export CLASSPATH=$CLASSPATH:myproject/lib/org.eclipse.emf.mwe.utils_0.7.2.v200908120417.jar
export CLASSPATH=$CLASSPATH:myproject/lib/org.eclipse.emf.ecore_2.5.0.v200906151043.jar
export CLASSPATH=$CLASSPATH:myproject/lib/oro-2.0.6.jar
export CLASSPATH=$CLASSPATH:myproject/lib/aopalliance.jar
export CLASSPATH=$CLASSPATH:myproject/lib/org.apache.commons.logging_1.0.4.v200904062259.jar
export CLASSPATH=$CLASSPATH:myproject/lib/org.eclipse.emf.common_2.5.0.v200906151043.jar
export CLASSPATH=$CLASSPATH:myproject/lib/org.eclipse.xtext_0.7.2.v200908120607.jar
export CLASSPATH=$CLASSPATH:myproject/lib/antlr-runtime-3.0.jar
export CLASSPATH=$CLASSPATH:myproject/lib/org.eclipse.emf.mwe.core_0.7.2.v200908120417.jar
export CLASSPATH=$CLASSPATH:myproject/lib/guice-1.0_patched.jar
Any ideas / help is appreciated!
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07597 seconds