Acceleo can run inside of Eclipse but you may want to to use your Acceleo generator out of your IDE to embed it inside of another application for example. Acceleo let you compile and run your generator in stand alone (AKA out of Eclipse) very easily.


In order to compile your Acceleo generator, you can use the maven plug-in or or can do it programmatically.

Programmatically

You can use the Java class, org.eclipse.acceleo.internal.parser.compiler.AcceleoParser to launch the compilation programmatically, its use being straightforward, it is not explained here. You just need to instantiate an AcceleoProject and then you need to call "buildAll(new BasicMonitor())".

Maven

The Acceleo Maven integration is will evolve independently of the releases of Acceleo, has such, it is recommended to check the Acceleo wiki for an up to date documentation on the subject: http://wiki.eclipse.org/Acceleo/Maven.

An action is available by right clicking on an Acceleo generator and selecting "Configure" and then "Generate pom.xml" to generate the skeleton of the pom.xml files necessary for the build. Some changes need to be done manually in order to have a valid build since some information cannot be computed by Acceleo.



An Acceleo generator can be launched from any J2SE-1.5+ application.

Registration

If you want to use your generator out of Eclipse, first you need to make sure that all the necessary elements are registered. There are two kinds of elements that need to be registered:

Package registration

You need to register the package that contains your classifiers, in order to use it inside of your generator. To do this, have a look at the method named "registerPackages" in the Java launcher generated next to your main module. You need to add the following piece of code:

        /**
         * @generated NOT
         */
        public void registerPackages(ResourceSet resourceSet) {
            super.registerPackages(resourceSet);
            if (!isInWorkspace(MyPackage.class)) {
                resourceSet.getPackageRegistry().put(MyPackage.eINSTANCE.getNsURI(), MyPackage.eINSTANCE);
            }
        }
        

The "@generated NOT" tag in the Javadoc is necessary to prevent the removal of your modification. Once the package is registered, Acceleo can use EMF to load your input model. If this does not work, you will see an error message stating that EMF cannot find the package with the uri "".

Resource Factory registration

Acceleo also needs to have a resource factory in order to load your model. By default, Acceleo knows how to load ".xmi" files but if you are using models with a different extension, for example ".uml", you need to tell Acceleo how to read those files. In order to do that, you need to have a look at the method named "registerResourceFactories" in the Java launcher to add the following piece of code for your meta-model. The following example is necessary for the use in stand alone of ".uml" models.

        /**
         * @generated NOT
         */
        @Override
        public void registerResourceFactories(ResourceSet resourceSet) {
            super.registerResourceFactories(resourceSet);
            resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION,
                                                                                    UMLResource.Factory.INSTANCE);
        }
        

Most of the time, you can use the following code, since EMF models are using by default the XMI resource serialization:

        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("myextension", new XMIResourceFactoryImpl());
        

Dependencies

Here is the list of the dependencies that you need to have in your build-path to run an Acceleo generator out of Eclipse:

Those jars can be found in the plug-ins folder of your Eclipse installation. And you need the following Acceleo components:

On top of those jars, you will also need the jar of your generator (you can obtain it by right clicking on it and selecting "Export..." and then in the "Plug-In Development" category choose "Deployable Plug-In and Fragment"). You can also build it thanks to maven. You will also need the jar of the meta-models that your generator are using and their dependencies. For example, for the UML to Java example available in Acceleo (File -> New -> Example -> Acceleo Model to Text -> UML to Java):

Run

In order to launch your generator, you need to instantiate it, to give it the URI of your model and the output folder where the code will be generated.

		String path = "C:Users/anUser/Desktop/generators/uml2java/model/example.uml";
		URI modelURI = URI.createFileURI(URI.decode(path));
		File targetFolder = new File("C:Users/anUser/Desktop/generators/uml2java/result");
		
		GenerateJava generator = new GenerateJava(modelURI, targetFolder, new ArrayList<Object>());
		generator.doGenerate(new BasicMonitor());
        

In this example, "GenerateJava" is the Java launcher of our Acceleo generator.