Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » MWE2 and xpand outside eclipse(use of xpand )
MWE2 and xpand outside eclipse [message #937659] Tue, 09 October 2012 06:41 Go to next message
Jim Van Dam is currently offline Jim Van DamFriend
Messages: 38
Registered: July 2009
Member
We are trying to use mwe2 and xpand inside a gwt application, but get the following exception:

	at com.google.inject.InjectorImpl$4.get(InjectorImpl.java:767) [com.google.inject-2.0.0.jar:]
	at org.eclipse.xtext.resource.XtextResourceFactory.createResource(XtextResourceFactory.java:19) [org.eclipse.xtext-2.0.0.jar:]
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.createResource(ResourceSetImpl.java:425) [ecore-2.4.2.jar:]
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.createResource(ResourceSetImpl.java:414) [ecore-2.4.2.jar:]
	at org.eclipse.xtext.resource.SynchronizedXtextResourceSet.createResource(SynchronizedXtextResourceSet.java:30) [org.eclipse.xtext-2.0.0.jar:]
	at org.eclipse.xtext.mwe.RuntimeResourceSetInitializer.getInitializedResourceSet(RuntimeResourceSetInitializer.java:76) [org.eclipse.xtext-2.0.0.jar:]
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.findModule(Mwe2Runner.java:112) [org.eclipse.emf.mwe2.launch-2.0.0.jar:]
	at nl.infodation.emr.pricingservice.rulegeneration.MyRunner.findModule(MyRunner.java:13) [classes:]
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:77) [org.eclipse.emf.mwe2.launch-2.0.0.jar:]


Cause: com.google.inject.ProvisionException: Guice provision errors:

1) Error injecting method, java.lang.NoClassDefFoundError: org/eclipse/xtext/impl/GrammarImpl
  at org.eclipse.xtext.conversion.impl.AbstractDeclarativeValueConverterService.setGrammar(AbstractDeclarativeValueConverterService.java:50)
  while locating org.eclipse.emf.mwe2.language.Mwe2ValueConverters
  while locating org.eclipse.xtext.conversion.IValueConverterService
    for field at org.eclipse.xtext.linking.impl.LinkingHelper.valueConverter(LinkingHelper.java:31)
  while locating org.eclipse.xtext.linking.impl.LinkingHelper
    for field at org.eclipse.xtext.parsetree.reconstr.impl.CrossReferenceSerializer.linkingHelper(CrossReferenceSerializer.java:34)
  while locating org.eclipse.xtext.parsetree.reconstr.impl.CrossReferenceSerializer
  while locating org.eclipse.xtext.parsetree.reconstr.ITokenSerializer$ICrossReferenceSerializer
    for field at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.crossRefSerializer(AbstractParseTreeConstructor.java:62)
  while locating org.eclipse.emf.mwe2.language.parseTreeConstruction.Mwe2ParsetreeConstructor
  while locating org.eclipse.xtext.parsetree.reconstr.IParseTreeConstructor
    for parameter 0 at org.eclipse.xtext.parsetree.reconstr.Serializer.<init>(Serializer.java:39)
  while locating org.eclipse.xtext.parsetree.reconstr.Serializer
  while locating org.eclipse.xtext.serializer.ISerializer
    for field at org.eclipse.xtext.resource.XtextResource.serializer(XtextResource.java:349)
  while locating org.eclipse.xtext.linking.lazy.LazyLinkingResource
  while locating org.eclipse.xtext.resource.XtextResource
Caused by: java.lang.NoClassDefFoundError: org/eclipse/xtext/impl/GrammarImpl
	at org.eclipse.xtext.impl.XtextFactoryImpl.createGrammar(XtextFactoryImpl.java:100)
	at org.eclipse.xtext.impl.XtextFactoryImpl.create(XtextFactoryImpl.java:63)
	at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.createObject(XMLHelperImpl.java:891)
	at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.createObject(XMLHelperImpl.java:928)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFactory(XMLHandler.java:2186)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectByType(XMLHandler.java:1330)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(XMLHandler.java:1468)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1019)
	at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:83)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1001)
	at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:712)
	at org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:169)
	at org.apache.xerces.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:496)
	at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:789)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:827)
	at org.apache.xerces.impl.XMLDocumentScannerImpl$ContentDispatcher.scanRootElementHook(XMLDocumentScannerImpl.java:1141)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1754)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:324)
	at org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:845)
	at org.apache.xerces.parsers.XML11Configuration.parse(XML11Configuration.java:768)
	at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:108)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1196)
	at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:555)
	at org.apache.xerces.jaxp.SAXParserImpl.parse(SAXParserImpl.java:289)
	at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:181)
	at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:180)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1445)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1241)
	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 org.eclipse.xtext.resource.SynchronizedXtextResourceSet.getResource(SynchronizedXtextResourceSet.java:23)
	at org.eclipse.xtext.parser.BaseEPackageAccess.loadResource(BaseEPackageAccess.java:52)
	at org.eclipse.xtext.parser.BaseEPackageAccess.loadGrammarFile(BaseEPackageAccess.java:44)
	at org.eclipse.xtext.service.GrammarProvider.getGrammar(GrammarProvider.java:49)
	at org.eclipse.emf.mwe2.language.services.Mwe2GrammarAccess.getGrammar(Mwe2GrammarAccess.java:744)
	at org.eclipse.xtext.conversion.impl.AbstractDeclarativeValueConverterService.setGrammar(AbstractDeclarativeValueConverterService.java:50)
	at $org.eclipse.xtext.conversion.impl.AbstractDeclarativeValueConverterService$$FastClassByGuice$$7fdb40ee.invoke(<generated>)
	at com.google.inject.internal.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
	at com.google.inject.SingleMethodInjector$1.invoke(SingleMethodInjector.java:59)
	at com.google.inject.SingleMethodInjector.inject(SingleMethodInjector.java:91)
	at com.google.inject.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:99)
	at com.google.inject.ConstructorInjector.construct(ConstructorInjector.java:94)
	at com.google.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:111)
	at com.google.inject.FactoryProxy.get(FactoryProxy.java:56)
	at com.google.inject.SingleFieldInjector.inject(SingleFieldInjector.java:56)
	at com.google.inject.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:99)
	at com.google.inject.ConstructorInjector.construct(ConstructorInjector.java:94)
	at com.google.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:111)
	at com.google.inject.SingleFieldInjector.inject(SingleFieldInjector.java:56)
	at com.google.inject.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:99)
	at com.google.inject.ConstructorInjector.construct(ConstructorInjector.java:94)
	at com.google.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:111)
	at com.google.inject.InjectorImpl$3.get(InjectorImpl.java:549)
	at com.google.inject.SingleFieldInjector.inject(SingleFieldInjector.java:56)
	at com.google.inject.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:99)
	at com.google.inject.ConstructorInjector.construct(ConstructorInjector.java:94)
	at com.google.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:111)
	at com.google.inject.FactoryProxy.get(FactoryProxy.java:56)
	at com.google.inject.SingleParameterInjector.inject(SingleParameterInjector.java:42)
	at com.google.inject.SingleParameterInjector.getAll(SingleParameterInjector.java:66)
	at com.google.inject.ConstructorInjector.construct(ConstructorInjector.java:84)
	at com.google.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:111)
	at com.google.inject.FactoryProxy.get(FactoryProxy.java:56)
	at com.google.inject.SingleFieldInjector.inject(SingleFieldInjector.java:56)
	at com.google.inject.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:99)
	at com.google.inject.ConstructorInjector.construct(ConstructorInjector.java:94)
	at com.google.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:111)
	at com.google.inject.FactoryProxy.get(FactoryProxy.java:56)
	at com.google.inject.InjectorImpl$4$1.call(InjectorImpl.java:758)
	at com.google.inject.InjectorImpl.callInContext(InjectorImpl.java:804)
	at com.google.inject.InjectorImpl$4.get(InjectorImpl.java:754)
	at org.eclipse.xtext.resource.XtextResourceFactory.createResource(XtextResourceFactory.java:19)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.createResource(ResourceSetImpl.java:425)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.createResource(ResourceSetImpl.java:414)
	at org.eclipse.xtext.resource.SynchronizedXtextResourceSet.createResource(SynchronizedXtextResourceSet.java:30)
	at org.eclipse.xtext.mwe.RuntimeResourceSetInitializer.getInitializedResourceSet(RuntimeResourceSetInitializer.java:76)
	at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.findModule(Mwe2Runner.java:112)


The java code that calls the mwe2 workflow looks like this:
Injector i = new Mwe2StandaloneSetup().createInjectorAndDoEMFRegistration();
Mwe2Runner runner = i.getInstance(MyRunner.class);
IWorkflowContext context = new WorkflowContextImpl();
context.put("rules", rules);
context.put("targetDir", file.getParentFile().getAbsolutePath());
context.put("ruleFile", file.getName());
runner.run("workflow.GenerateRules", new HashMap<String, String>(), context);        


As the GrammarImpl is in the xtext-2.0.0.jar which is obviously there looking at the call stack, it looks like it has something to do with providing the right paths to the runner so the injected provider can find everything.
Does anybody recognize this or has experience using mwe2 and xpand in a web app outside eclipse?

Jim
Re: MWE2 and xpand outside eclipse [message #937755 is a reply to message #937659] Tue, 09 October 2012 08:27 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 360
Registered: July 2009
Location: Dortmund
Senior Member

Jim,

this looks indeed strange. I could not really see why this should happen. Please make sure that the Jar that you have on the classpath really has this class (I could not imagine why it shouldn't if you got it from official sites). The other thing I would do is to set an exception breakpoint on NoClassDefFoundError and inspect the classloader.

Regards,
~Karsten


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: MWE2 and xpand outside eclipse [message #937828 is a reply to message #937755] Tue, 09 October 2012 09:54 Go to previous messageGo to next message
Jim Van Dam is currently offline Jim Van DamFriend
Messages: 38
Registered: July 2009
Member
Hi Karsten,

Yes, it looks like a classpath thing.
It's a ModuleClassLoader and I see lots of classes from org.eclipse.xtext.impl, but I also see a warning just before the classdefnotfound:
 java.lang.SecurityException: class "org.eclipse.emf.ecore.impl.MinimalEObjectImpl$Container"'s signer information does not match signer information of other classes in the same package

that was the cause of not loading the GrammarImpl, because I had more than one jar with emf.ecore in it. I removed it and the only other thing I had to do was to override the getPaths() to let the current classloader look for the mwe2 file and add that to the paths list so it can be used by the RuntimeResourceSetInitializer. Now it's at least starting my workflow.

Thanks for the quick response.
Re: MWE2 and xpand outside eclipse [message #937924 is a reply to message #937828] Tue, 09 October 2012 11:37 Go to previous messageGo to next message
Jim Van Dam is currently offline Jim Van DamFriend
Messages: 38
Registered: July 2009
Member
Calling the xpand template now fails. Cannot find the definition in the XpandExecutionContextImpl in method findTemplate through xpand.expression.ResourceManagerDefault.loadResource:
final InputStream in = ResourceLoaderFactory.createResourceLoader()
				.getResourceAsStream(resourceName);

The resourceName is "templates/RulesRoot.xpt" and null is returned.
While if I do this in my runner:
URL xpandTemplate = currentThreadClassLoader.getResource("templates/RulesRoot.xpt");

It is found, so the ResourceManager does not have the required paths probably.
Something todo with classpath because of running outside eclipse.

Question is: how do I configure the resourcemanager correctly?
Re: MWE2 and xpand outside eclipse [message #937943 is a reply to message #937924] Tue, 09 October 2012 11:58 Go to previous messageGo to next message
Jim Van Dam is currently offline Jim Van DamFriend
Messages: 38
Registered: July 2009
Member
Zooming in now:
public URL getResource(String path) {
	URL url = loadDirectly(path);
	if (url == null) {
		url = loadFromBaseURL(path);
	}
	if (url == null) {
		url = loadFromContextClassLoader(path);
	}
	if (url == null) {
		url = loadFromFile(path);
	}
	return url;
}

In mwe.core.resources.AbstractResourceLoader is the culprit (when used outside eclipse).
loadFromBaseURL takes the full path of the jar and appends the "templates/RulesRoot.xpt".
This url is returned and of course results in not found when trying to load the resource.
If I null the return value to make it go to loadFromContextClassLoader it is correctly found and returned.
The loadFromBaseURL uses url.getContent() and that returns a path string <fullpath>/org.eclipse.emf.mwe.core-1.1.0.jar/templates/RulesRoot.xpt" making it think the url is valid.

Any suggestions for workarounds or proper solutions?
Re: MWE2 and xpand outside eclipse [message #937969 is a reply to message #937943] Tue, 09 October 2012 12:23 Go to previous message
Jim Van Dam is currently offline Jim Van DamFriend
Messages: 38
Registered: July 2009
Member
Ok, solved. For anyone using JBoss and a webapp with mwe2/xpand:
The virtual file system feature of JBoss makes a path like <somename>.jar/templates/<your templatename>.xpt return a URI that returns non-null on getContent() even though the URI does not resolve to a valid resource.
This makes the loadFromBaseURL return an invalid URL and stops xpand from reading the template.
Fortunately you can do something like
System.setProperty(ResourceLoaderFactory.PARAM_RESOURCELOADER_CLASS, ContextFirstResourceLoader.class.getName()) 
and write your own resource loader that first looks in the context or does extra checks before returning the URL. This solved my problem.
Previous Topic:[Acceleo] StringIndexOutOfBoundsException during Acceleo Build
Next Topic:[Acceleo 3] Multiple metamodels
Goto Forum:
  


Current Time: Sat Dec 20 17:24:56 GMT 2014

Powered by FUDForum. Page generated in 0.09607 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software