Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » MWE2 Running as Standalone
MWE2 Running as Standalone [message #727602] Wed, 21 September 2011 15:52 Go to next message
Daniel Missing name is currently offline Daniel Missing nameFriend
Messages: 101
Registered: July 2011
Senior Member
Hi.

I just wanted to deploy my compiler as a standalone package. I created a CLI class which triggers the MWE2 Runner using the file specified using the arguments:

	/**
	 * Runs the specified MWE file using the {@link Mwe2Runner} class created by
	 * a new {@link Mwe2StandaloneSetup} instance.
	 * 
	 * @param mweFile the MWE file to execute
	 */
	public static void runAsStandalone(File mweFile) {
		if (mweFile == null) {
			throw new IllegalArgumentException("MWE file (mwe) must be set!"); //$NON-NLS-1$
		}

		if (!mweFile.exists() || !mweFile.isFile()) {
			throw new IllegalArgumentException("The specified MWE file \"" + mweFile.getAbsolutePath() + "\" does not exist oder is no file"); //$NON-NLS-1$ //$NON-NLS-2$
		}

		Injector injector = new Mwe2StandaloneSetup().createInjectorAndDoEMFRegistration();
		Mwe2Runner mweRunner = injector.getInstance(Mwe2Runner.class);
		Map<String, String> empty = Collections.emptyMap();
		mweRunner.run(URI.createFileURI(mweFile.getAbsolutePath()), empty);
	}


Afterwards I exported the main dsl project using the Export as Runnable Jar to include all dependencies.

But I only get this error if I invoke the compiler:
> java -cp .;build -jar MyDslRuntime.jar build/CompileToC.mwe2

0    [main] FATAL     at.mydsl.CLI  - MyDsl Build Failed
java.lang.IllegalStateException: Couldn't find module CompileToC
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:79)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:73)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:64)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:55)
        at at.mydsl.MyDslCompiler.runAsStandalone(MyDslCompiler.java:216)
        at at.mydsl.CLI.main(CLI.java:33)


The I took a look at the Mwe2Runner.java and found this wierd code:

Mwe2Runner:62-66
EObject eObject = resource.getContents().get(0);
if (eObject instanceof Module) {
	run(((Module) eObject).getCanonicalName(), params);
	return;
}

Mwe2Runner:76-80
ppublic void run(String moduleName, Map<String, String> params, IWorkflowContext ctx) {
	Module module = findModule(moduleName);
	if (module == null) {
		throw new IllegalStateException("Couldn't find module "+moduleName);
	}


The Module instance is available on line 64 but only the name gets bypassed ot the other run method. There it tries to resolve the module by name. It seems the loaded module doesn't get registered correctly to find it via findModule.


Any Ideas?

Greetings
Daniel
Re: MWE2 Running as Standalone [message #727690 is a reply to message #727602] Wed, 21 September 2011 20:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
Hi,

why do you reinvent the wheel:

public class Main {

	public static void main(String[] args) {
		Mwe2Launcher.main(new String[]{"src/test.mwe2"});
	}

}


~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: MWE2 Running as Standalone [message #727900 is a reply to message #727690] Thu, 22 September 2011 07:36 Go to previous messageGo to next message
Daniel Missing name is currently offline Daniel Missing nameFriend
Messages: 101
Registered: July 2011
Senior Member
Thanks for that hint but it has nothing to do with my problem. After changing the code I still get this error:

C:\Dev\tmp\standalone test> java -classpath .;MyDslRuntime.jar -jar MyDslRuntime.jar CompileToC.mwe2

0    [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher  - Couldn't find module C:\Dev\tmp\standalone test\CompileToC.mwe2
java.lang.IllegalStateException: Couldn't find module C:\Dev\tmp\standalone test\CompileToC.mwe2
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:79)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:73)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:76)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
        at at.mydsl.compiler.MyDslCompiler.runAsStandalone(MyDslCompiler.java:213)
        at at.mydsl.compiler.CLI.main(CLI.java:33)



It also seems the Mwe2Launcher does not recognize file-paths very well. Therefore I tried to bypass the file-uri:
	/**
	 * Runs the specified MWE file using the {@link Mwe2Runner} class created by
	 * a new {@link Mwe2StandaloneSetup} instance.
	 * 
	 * @param mweFile the MWE file to execute
	 */
	public static void runAsStandalone(File mweFile) {
		if (mweFile == null) {
			throw new IllegalArgumentException("MWE file (mwe) must be set!"); //$NON-NLS-1$
		}

		if (!mweFile.exists() || !mweFile.isFile()) {
			throw new IllegalArgumentException("The specified MWE file \"" + mweFile.getAbsolutePath() + "\" does not exist oder is no file"); //$NON-NLS-1$ //$NON-NLS-2$
		}

		Mwe2Launcher.main(new String[] {mweFile.toURI().toString()});
	}


But this also does not solve the problem:

C:\Dev\tmp\standalone test>java -classpath .;MyDslRuntime.jar -jar MyDslRuntime.jar CompileToC.mwe2
1    [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher  - Couldn't find module CompileToC
java.lang.IllegalStateException: Couldn't find module CompileToC
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:79)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:73)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:64)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:55)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
        at at.mydsl.compiler.MyDslCompiler.runAsStandalone(MyDslCompiler.java:208)
        at at.mydsl.compiler.CLI.main(CLI.java:33)


It seems the Module loaded via...
Mwe2Runner.java:58-70
public void run(URI createURI, Map<String, String> params, IWorkflowContext ctx) {
	Resource resource = resourceSetProvider.get().getResource(createURI, true);
	if (resource != null) {
		if (!resource.getContents().isEmpty()) {
			EObject eObject = resource.getContents().get(0);
			if (eObject instanceof Module) {
				run(((Module) eObject).getCanonicalName(), params);
				return;
			}
		}
	}
	throw new IllegalArgumentException("Couldn't load module from URI " + createURI);
}

... does not get registered within the initializer.getInitializedResourceSet(). (findModule) and therefore the module cannot be found. I'm wondering why the Mwe2Runner does not already use the module instance of Mwe2Runner.java:64 instead of bypass the canonicalName and reresolve the module by name.

[Updated on: Thu, 22 September 2011 07:51]

Report message to a moderator

Re: MWE2 Running as Standalone [message #727902 is a reply to message #727900] Thu, 22 September 2011 07:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
Hi,

are you sure your jar is sufficient?

~Christian


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: MWE2 Running as Standalone [message #727931 is a reply to message #727900] Thu, 22 September 2011 08:58 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3108
Registered: July 2009
Senior Member
Hi Daniel,

please try to use a path without a space just to make sure there is no
bug with path escaping.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

On 22.09.11 09:36, Daniel wrote:
> Thanks for that hint but it has nothing to do with my problem. After
> changing the code I still get this error:
>
>
> C:\Dev\tmp\standalone test> java -classpath .;MyDslRuntime.jar -jar
> MyDslRuntime.jar CompileToC.mwe2
>
> 0 [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher - Couldn't find
> module C:\Dev\tmp\standalone test\CompileToC.mwe2
> java.lang.IllegalStateException: Couldn't find module
> C:\Dev\tmp\standalone test\CompileToC.mwe2
> at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:79)
> at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:73)
> at
> org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:76)
> at
> org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
> at at.mydsl.compiler.MyDslCompiler.runAsStandalone(MyDslCompiler.java:213)
> at at.mydsl.compiler.CLI.main(CLI.java:33)
>
>
>
>
Re: MWE2 Running as Standalone [message #727945 is a reply to message #727902] Thu, 22 September 2011 09:22 Go to previous messageGo to next message
Daniel Missing name is currently offline Daniel Missing nameFriend
Messages: 101
Registered: July 2011
Senior Member
I created a test project for you. To reproduce it:

1. I imported the flowerdsl and removed the generator workflow component
2. I created a compiler package and added a custom CLI class and a base-template
3. I created a custom compiler workflow component which allows to set the template from outside
4. I created a new project storing the xtend templates and added the required dependencies.
5. I created a new run-configuration pointing to the CLI
6. I deployed the main dsl project as runnable jar using the created run-configuration and added all dependencies to the package.
7. I created two templates and deployed the template project as normal jar without dependencies.
8. I created two workflow files for compiling the two templates.
9. I created a dummy dsl file
10. I tried to trigger the compiler using my CLI class -> here it is: the error

C:\Dev\workspace\flower-standalone>GenerateMyTemplate.bat
Invoking Flower Compiler
1    [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher  - Couldn't find module GenerateMyTemplate
java.lang.IllegalStateException: Couldn't find module GenerateMyTemplate
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:79)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:73)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:64)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:55)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
        at org.eclipse.xtext.example.fowlerdsl.compiler.CLI.main(CLI.java:30)


You can find the deployed stuff in the flower-standalone directory. I excluded the generated FlowerRuntime.jar because of the filesize. Simply create it by reproducing step 5 and 6.

  • Attachment: flowerdsl.zip
    (Size: 249.46KB, Downloaded 169 times)
Re: MWE2 Running as Standalone [message #728048 is a reply to message #727945] Thu, 22 September 2011 13:04 Go to previous messageGo to next message
Daniel Missing name is currently offline Daniel Missing nameFriend
Messages: 101
Registered: July 2011
Senior Member
After hours and hours of work I finally got the solution: The java executable ignores the -classpath if you use -jar Therefore the mwe2 file is not within the classpath and the module within it cannot be found. Therefore you have to invoke the compiler like this:
java -cp .;MyTemplates.jar;MyDslRuntime.jar at.mydsl.compiler.CLI CompileToC.mwe2


Afterwards I had to add some additional dependencies to the classpath and I'm fine to run it. There's only one problem left: You cannot package all jars together in one. Why? A lot of jars have files within the root directory like message properties and the plugin.xml . If I package them together in one they get overwritten and some classes throw an exception because they cannot find their messages. For the future you should definitly provide some kind of standalone jars which allow an easy execution of MWE files without hundreds of dependencies.

However MWE seems to be quite buggy/uncomfortable outside of Eclipse. I just tried to create an ANT task for compilation too: And again no module can be found. I created my own MWE2Runner which directly works with the module and does not work with the canonical name and guess what: Everything works fine Smile

Re: MWE2 Running as Standalone [message #883224 is a reply to message #728048] Fri, 08 June 2012 04:48 Go to previous message
Andy Gotz is currently offline Andy GotzFriend
Messages: 32
Registered: July 2010
Member
Hi,

I am interested in your MWE2Runner you created. We have a similar need. Could you share it with us?

Thanks

Andy
Previous Topic:Scoping docs
Next Topic:Who to get the content of a Multiline-Comment?
Goto Forum:
  


Current Time: Wed Oct 21 14:45:50 GMT 2020

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

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

Back to the top