Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Using Xtext and Code Generator without Runtime(Using Xtext and Code Generator without Runtime)
Using Xtext and Code Generator without Runtime [message #1478261] Tue, 18 November 2014 09:33 Go to next message
Eclipse UserFriend
Hi everybody,

I have developed a dsl and a generator for this dsl to generate some java files.
Now I want to use this generator to generate the java files but according a special file which must be an input and it must be available without Eclipse Runtime Version or Workbench.

Bests,
Parisa
Re: Using Xtext and Code Generator without Runtime [message #1478298 is a reply to message #1478261] Tue, 18 November 2014 10:11 Go to previous messageGo to next message
Eclipse UserFriend
Create a main class that reads your DSL files and invoke the generator. Then create a launch configuration. With the export wizard you can generate an executable Jar.

Alternatively provide a MWE2 workflow that does the process mentioned above. Then create a launch config for class org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher. Proceed like above.

Regards,
~Karsten
Re: Using Xtext and Code Generator without Runtime [message #1478299 is a reply to message #1478261] Tue, 18 November 2014 10:11 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

(1) adapt the generatorFragment in the workflow to create a java main

fragment = generator.GeneratorFragment auto-inject {
    			generateJavaMain = true
    		}

(2) regenerate the language. you find now a java main generated for the generator (you may use this one or adapt it for your needs)
(3) run the main once in eclipse
(4) use the export -> java -> runnable jar file wizard to create a all in one jar
Re: Using Xtext and Code Generator without Runtime [message #1479208 is a reply to message #1478299] Wed, 19 November 2014 03:44 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

Thanks a lot for your help. I have done till step 3. How can I run main? it needs a EMF Resource. What should I sent to this method as parameter?

bests,
Parisa
Re: Using Xtext and Code Generator without Runtime [message #1479209 is a reply to message #1479208] Wed, 19 November 2014 03:45 Go to previous messageGo to next message
Eclipse UserFriend
hi the parameter is the model file to process
Re: Using Xtext and Code Generator without Runtime [message #1479223 is a reply to message #1479209] Wed, 19 November 2014 03:59 Go to previous messageGo to next message
Eclipse UserFriend
Actually I have changed the main method like following:
public static void main(String[] args) {
		String s="C:\\ ... \\org.xtext.example.pro1\\pro1\\pro1.pro1";
		//if (args.length==0) {
		//	System.err.println("Aborting: no path to EMF resource provided!");
		//	return;
		//}
		Injector injector = new org.xtext.example.mydsl.Pro1StandaloneSetup().createInjectorAndDoEMFRegistration();
		Main main = injector.getInstance(Main.class);
		
		main.runGenerator(s);
	}

but I get this error:
Exception in thread "main" java.lang.RuntimeException: Cannot create a resource for 'c:\ ... \org.xtext.example.pro1\pro1\pro1.pro1'; a registered resource factory is needed
	at org.eclipse.xtext.resource.XtextResourceSet.getResource(XtextResourceSet.java:198)


and pro1.pro1 ist the file which I have created in Runtime Workbench.
Re: Using Xtext and Code Generator without Runtime [message #1479232 is a reply to message #1479223] Wed, 19 November 2014 04:06 Go to previous messageGo to next message
Eclipse UserFriend
hi,

are you sure the file extension of your dsl is pro1?
and the uri should be file:///c:.... i think
Re: Using Xtext and Code Generator without Runtime [message #1479246 is a reply to message #1479232] Wed, 19 November 2014 04:24 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

Yes I have generated pro1.pro1 file myself and I generated all java files which I need with this Model and my generator (But all of them in runtime).

I have only copied pro1.pro1 from my runtime workbench and pased it in a folder in my xtext project because I want to run it without runtime.

Want I want to have is following:
I want to do a Rightclick on a xml file in my project and select an option for example "Generate File".
and then the dsl that I have developed can make a model from this xml file and then generate all the java files that I need. Smile
Re: Using Xtext and Code Generator without Runtime [message #1479270 is a reply to message #1479246] Wed, 19 November 2014 04:45 Go to previous messageGo to next message
Eclipse UserFriend
sorry but that should work. can you try this with a brand new mydsl project? the Pro1StandaloneSetup should have registered the resource factory.
can you post the content of the generated base class of Pro1StandaloneSetup
Re: Using Xtext and Code Generator without Runtime [message #1479275 is a reply to message #1479270] Wed, 19 November 2014 04:50 Go to previous messageGo to next message
Eclipse UserFriend
hi,

are this righclick thing will not work this way in eclipse. be aware of that
Re: Using Xtext and Code Generator without Runtime [message #1479284 is a reply to message #1479275] Wed, 19 November 2014 05:00 Go to previous messageGo to next message
Eclipse UserFriend
This is my Pro1StandaloneSetup.java
/*
* generated by Xtext
*/
package org.xtext.example.mydsl;

/**
 * Initialization support for running Xtext languages 
 * without equinox extension registry
 */
public class Pro1StandaloneSetup extends Pro1StandaloneSetupGenerated{

	public static void doSetup() {
		new Pro1StandaloneSetup().createInjectorAndDoEMFRegistration();
	}
}


Re: Using Xtext and Code Generator without Runtime [message #1479314 is a reply to message #1479284] Wed, 19 November 2014 05:34 Go to previous messageGo to next message
Eclipse UserFriend
i actually ment Pro1StandaloneSetupGenerated
Re: Using Xtext and Code Generator without Runtime [message #1479356 is a reply to message #1479314] Wed, 19 November 2014 06:12 Go to previous messageGo to next message
Eclipse UserFriend
/*
* generated by Xtext
*/
package org.xtext.example.mydsl;

import org.eclipse.emf.ecore.EPackage;
import org.eclipse.xtext.ISetup;
import org.eclipse.emf.ecore.resource.Resource;

import com.google.inject.Guice;
import com.google.inject.Injector;

/**
 * Generated from StandaloneSetup.xpt!
 */
@SuppressWarnings("all")
public class Pro1StandaloneSetupGenerated implements ISetup {

	public Injector createInjectorAndDoEMFRegistration() {
		org.eclipse.xtext.common.TerminalsStandaloneSetup.doSetup();

		Injector injector = createInjector();
		register(injector);
		return injector;
	}
	
	public Injector createInjector() {
		return Guice.createInjector(new org.xtext.example.mydsl.Pro1RuntimeModule());
	}
	
	public void register(Injector injector) {
	if (!EPackage.Registry.INSTANCE.containsKey("http://www.xtext.org/example/mydsl/Pro1")) {
		EPackage.Registry.INSTANCE.put("http://www.xtext.org/example/mydsl/Pro1", org.xtext.example.mydsl.pro1.Pro1Package.eINSTANCE);
	}

		org.eclipse.xtext.resource.IResourceFactory resourceFactory = injector.getInstance(org.eclipse.xtext.resource.IResourceFactory.class);
		org.eclipse.xtext.resource.IResourceServiceProvider serviceProvider = injector.getInstance(org.eclipse.xtext.resource.IResourceServiceProvider.class);
		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("pro1", resourceFactory);
		org.eclipse.xtext.resource.IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("pro1", serviceProvider);
		


	}
}


Re: Using Xtext and Code Generator without Runtime [message #1479368 is a reply to message #1479356] Wed, 19 November 2014 06:21 Go to previous messageGo to next message
Eclipse UserFriend
hi having a look at this i have no idea why that doesnt work.
did you try it with a brand new mydsl project?
Re: Using Xtext and Code Generator without Runtime [message #1479402 is a reply to message #1479368] Wed, 19 November 2014 06:57 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
I have tried it with mydsl but I have still the error
Exception in thread "main" java.lang.RuntimeException: Cannot create a resource for 'c:\ ... \org.xtext.example.mydsl\dslmodel\sample.mydsl'; a registered resource factory is needed
	at org.eclipse.xtext.resource.XtextResourceSet.getResource(XtextResourceSet.java:198)
	at org.eclipse.xtext.resource.SynchronizedXtextResourceSet.getResource(SynchronizedXtextResourceSet.java:26)
	at org.xtext.example.mydsl.generator.Main.runGenerator(Main.java:50)
	at org.xtext.example.mydsl.generator.Main.main(Main.java:32)
Re: Using Xtext and Code Generator without Runtime [message #1479408 is a reply to message #1479402] Wed, 19 November 2014 07:02 Go to previous messageGo to next message
Eclipse UserFriend
Parisa Moosavi wrote on Wed, 19 November 2014 12:57
Hi,
I have tried it with mydsl but I have still the error
Exception in thread "main" java.lang.RuntimeException: Cannot create a resource for 'c:\ ... \org.xtext.example.mydsl\dslmodel\sample.mydsl'; a registered resource factory is needed
	at org.eclipse.xtext.resource.XtextResourceSet.getResource(XtextResourceSet.java:198)
	at org.eclipse.xtext.resource.SynchronizedXtextResourceSet.getResource(SynchronizedXtextResourceSet.java:26)
	at org.xtext.example.mydsl.generator.Main.runGenerator(Main.java:50)
	at org.xtext.example.mydsl.generator.Main.main(Main.java:32)

  • Attachment: 1.png
    (Size: 26.81KB, Downloaded 160 times)
Re: Using Xtext and Code Generator without Runtime [message #1479409 is a reply to message #1479408] Wed, 19 November 2014 07:04 Go to previous messageGo to next message
Eclipse UserFriend
I have send a picture that shows my new mydsl project.
What is src-gen ?
My model is in dslmodel folder.
Re: Using Xtext and Code Generator without Runtime [message #1479444 is a reply to message #1479409] Wed, 19 November 2014 07:37 Go to previous messageGo to next message
Eclipse UserFriend
How can I register a resource factory ?
Re: Using Xtext and Code Generator without Runtime [message #1479465 is a reply to message #1479444] Wed, 19 November 2014 07:57 Go to previous messageGo to next message
Eclipse UserFriend
I have find it out if I paste my pro1.pro1 or sample.mydsl in the root directory of the project then main method can work fine.
Re: Using Xtext and Code Generator without Runtime [message #1479470 is a reply to message #1479465] Wed, 19 November 2014 08:03 Go to previous messageGo to next message
Eclipse UserFriend
but I can not see the generated java files ?
Re: Using Xtext and Code Generator without Runtime [message #1479471 is a reply to message #1479470] Wed, 19 November 2014 08:04 Go to previous messageGo to next message
Eclipse UserFriend
where did you look for? did you debug your IGenerator?
Re: Using Xtext and Code Generator without Runtime [message #1479486 is a reply to message #1479471] Wed, 19 November 2014 08:16 Go to previous messageGo to next message
Eclipse UserFriend
p.s. it by default generates to src-gen as it looks
Re: Using Xtext and Code Generator without Runtime [message #1479540 is a reply to message #1479486] Wed, 19 November 2014 09:13 Go to previous messageGo to next message
Eclipse UserFriend
but they are not my java classes , only dsl classes.
Re: Using Xtext and Code Generator without Runtime [message #1479541 is a reply to message #1479540] Wed, 19 November 2014 09:14 Go to previous messageGo to next message
Eclipse UserFriend
sorry without any reproducable example i cannot help.
did you debug your igenerator as i suggested?
Re: Using Xtext and Code Generator without Runtime [message #1479608 is a reply to message #1479541] Wed, 19 November 2014 10:26 Go to previous messageGo to next message
Eclipse UserFriend
Yes, I have done the four steps wich you suggested. I have called the mydsl.jar file and sent the name of sample.mydsl file as argument.
But nothing happened.
Re: Using Xtext and Code Generator without Runtime [message #1479619 is a reply to message #1479608] Wed, 19 November 2014 10:37 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

as i cannot reproduce this with the xtext hello world example i cannot tell what goes wrong in your example.
either you share your complete code or have to debug the problem yourself.
try it with the hello world example yourself. then have a look what is different in your case.
Re: Using Xtext and Code Generator without Runtime [message #1480495 is a reply to message #1479619] Thu, 20 November 2014 03:21 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

Thanks a lot. I can now generate what I need without runtime. Smile
Is there a Handbook about Xtext?
For example for what I wanted to do, I thought that I must write a lot to do it but with your suggestion I have done it very easier than I thought.

Where I can find this documentations?


Re: Using Xtext and Code Generator without Runtime [message #1480505 is a reply to message #1480495] Thu, 20 November 2014 03:31 Go to previous message
Eclipse UserFriend
Hi,

i am not sure what you are talking about.
there is http://www.eclipse.org/Xtext/documentation.html
https://wiki.eclipse.org/Xtext/FAQ
a tons of blogs
and Lorenzo Bettinis Book "Implementing Domain-Specific Languages with Xtext and Xtend"
but i dont know if they cover this topic

in general for advanced stuff you have to look at the code
Previous Topic:How to trigger Java code generation from Xtext generated Xtend sources
Next Topic:Removing unnecessary files in ProjectCreator
Goto Forum:
  


Current Time: Mon Nov 03 05:02:05 EST 2025

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

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

Back to the top