Exporting Parser+Generator as standalone jar file [message #908976] |
Thu, 06 September 2012 06:34  |
Eclipse User |
|
|
|
Hi All,
I have developed a grammar of my language via Xtext and subsequently written the code generator via Xtend.
Now, I want others to design their systems following my language and automatically translate their models into another model via the generator.
One can easily do this by using my parser+generator as plugin to eclipse.
However, my main concern is to let others use my parser+generator as standalone jar file. So, they can download such a jar file into their desktop and simply click it to be able design their models in my language and do translatation with the generator.
So, could you please let me know the instructions to follow in order to export my xtext(and xtend) framework as standalone jar file ?
Thanks a lot in advance.
|
|
|
|
|
|
|
|
|
|
|
Re: Exporting Parser+Generator as standalone jar file [message #912444 is a reply to message #912400] |
Thu, 13 September 2012 11:41   |
Eclipse User |
|
|
|
Hi Christian,
I have just copied and pasted this from the arguments of the configuration that opens
eclipse editor when run. Do you think that I left the arguments empty for the Java Launch configuration ?
My Main.java has the following content:
public class Main {
public static void main(String[] args) {
if (args.length==0) {
System.err.println("Aborting: no path to EMF resource provided!");
return;
}
Injector injector = new org.xtext.example.mydsl.XcDStandaloneSetupGenerated().createInjectorAndDoEMFRegistration();
Main main = injector.getInstance(Main.class);
main.runGenerator(args[0]);
}
@Inject
private Provider<ResourceSet> resourceSetProvider;
@Inject
private IResourceValidator validator;
@Inject
private IGenerator generator;
@Inject
private JavaIoFileSystemAccess fileAccess;
protected void runGenerator(String string) {
// load the resource
ResourceSet set = resourceSetProvider.get();
Resource resource = set.getResource(URI.createURI(string), true);
// validate the resource
List<Issue> list = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
if (!list.isEmpty()) {
for (Issue issue : list) {
System.err.println(issue);
}
return;
}
// configure and start the generator
fileAccess.setOutputPath("src-gen/");
generator.doGenerate(resource, fileAccess);
System.out.println("Code generation finished.");
}
}
So, is what you are suggesting to add the following snippet inside the above main.java ? THe below snippet is obtained from "StandaloneSetupGenerated.java"
public Injector createInjectorAndDoEMFRegistration() {
// register default ePackages
if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("ecore"))
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
"ecore", new org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl());
if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey("xmi"))
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
"xmi", new org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl());
if (!EPackage.Registry.INSTANCE.containsKey(org.eclipse.xtext.XtextPackage.eNS_URI))
EPackage.Registry.INSTANCE.put(org.eclipse.xtext.XtextPackage.eNS_URI, org.eclipse.xtext.XtextPackage.eINSTANCE);
Injector injector = createInjector();
register(injector);
return injector;
}
public Injector createInjector() {
return Guice.createInjector(new org.xtext.example.mydsl.XcDRuntimeModule());
}
public void register(Injector injector) {
if (!EPackage.Registry.INSTANCE.containsKey("...")) {
EPackage.Registry.INSTANCE.put("...", org.xtext.example.mydsl.myDsl.MyDslPackage.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("xcd", resourceFactory);
org.eclipse.xtext.resource.IResourceServiceProvider.Registry.INSTANCE.getExtensionToFactoryMap().put("xcd", serviceProvider);
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06973 seconds