How can I produce a standalone application with the DSL editor I created? This question pops up sometimes in the forum. I will show you how to set up a rather minimal RCP application that enables using the DSL editor created with Xtext. As an example I take the simple Xtext project that you get when you create Xtext projects with the default settings.
Sources for the example project can be downloaded here.
1. Create the Xtext project
Open the menu File / New / Project / Xtext and select Xtext Project. Click Next and then Finish.
You will get the three projects
2. Create a Plugin Project for your product
- Create a new Plug-in project with File / New / Project / Plug-in Development / Plug-in Project and press Next.
- Enter the project name “org.xtext.example.mydsl.product” and press Next.
- In the Options section deselect “Generate an activator…” and “This plug-in will make contributions to the UI”
- Press Finish
- Generate the DSL implementation by right-click on the GenerateMyDsl.mwe2 and select Run As / MWE2 Workflow.
3. Create a Feature Project for your DSL
Now we will create a Feature that contains only our DSL specific plugins.
- Create a new Feature projectwith File / New / Project / Plug-in Development / Feature Project and press Next.
- Give it the name “org.xtext.example.mydsl.feature” and press Finish.
- Open the feature.xml and go to the Plug-ins page.
- Add your DSL plugins:
4. Create a Feature Project for the Runtime
A second feature should bundle all the plugins that are required to get the DSL editor running on the RCP platform. This is indeed the most cumbersome work. What exectly is required in a minimal setup to get the editor working? Your DSL editor might need some more plugins than the ones listed here, but for the minimal Xtext project that comes out of the wizard the following list will give you a good starting point.
Now create another Feature Project “org.xtext.example.mydsl.platform.feature” like above. Add the following plugins:
ATTENTION: Xtext currently requires com.google.collect in a version < 1.0. You might have installed different versions of the plugin in your IDE, and to be sure that the right one will be picked, specify the version of that plugin explicitly. In my environment the version is v201008251220. You can identify the right version if you open the Plugin-Dependencies of the org.xtext.example.mydsl project in the Package Explorer and search for the com.google.collect plugin.
5. Define the org.eclipse.core.runtime.products extension
- Open the MANIFEST.MF in org.xtext.example.mydsl.product.
- Go to the “Dependencies” page and add org.eclipse.core.runtime as required plugin.
- Now go to the Extensions page. Click the “Add…” button and select the org.eclipse.core.runtime.products extension point.
- Select the extension and enter ID “product” in the Extension Details
- Right-click on the extension and select New / product.
- Enter value for application: org.eclipse.ui.ide.workbench
- Enter the name property for the product (“MyDSL”)
- Right-click on “MyDSL (product)” and select New / property.
- Enter name=appName, value=MyDSL in the Extension Element Details.
Go to the “plugin.xml” page. The content should now be:
<?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.4"?> <plugin> <extension id="product" point="org.eclipse.core.runtime.products"> <product application="org.eclipse.ui.ide.workbench" name="MyDSL"> <property name="appName" value="MyDSL"> </property> </product> </extension> </plugin>
6. Create the Product Configuration
In the org.xtext.example.mydsl.product project create a new Product Configuration file “MyDSL.product” (File / New / Plug-in Development / Product Configuration).
Open the MyDSL.product file. On the Overview page do:
- set name “MyDSL”
- select Product org.xtext.example.mydsl.product.product
- select Application org.eclipse.ui.ide.workbench
- select “The product conifguration is based : features“
Go to the Dependencies page and add the both features
7. Starting the product for testing
On the Overview page you can directly start the product by clicking on the link “Launch an Eclipse Application”. In ideal case it should already work, but you might have to adjust the run configuration that was created. If you see in the console log errors like
MESSAGE Bundle org.eclipse.xtext_1.0.1.v201008251220  was not resolved. !SUBENTRY 2 org.eclipse.xtext 2 0 2010-11-12 14:00:47.803 !MESSAGE Missing required bundle org.eclipse.xtext.util_1.0.1. !SUBENTRY 2 org.eclipse.xtext 2 0 2010-11-12 14:00:47.803 !MESSAGE Missing optionally required bundle org.eclipse.emf.codegen_2.5.0.
then close the application again (which should have started instead of these errors). Your DSL editor won’t work then.
Open Run / Run Configurations / Eclipse Application / MyDSL.product and open the Plug-ins page. Press the “Validate Plug-ins” button. If the validation fails for Xtext plugins then we have a problem.
The validation failures for the plugins
can be ignored.
The possible problem causing these errors can be again the wrong version of com.google.collect that was selected for the run configuration. Make sure that version 0.8.0 is selected and 1.0.0 not.
Press “Validate Plug-ins” again. Now no Xtext plugin should fail validation. The others mentioned above can be ignored for now.
You might have to adjust also the memory settings if you experience OutOfMemory problems. This can be done on the Arguments page in the “VM argument” field. The settings I have chosen are:
8. Test the product
If everything is now configured correctly start the application again. The application should now start successfully and show a minimal Eclipse IDE.
Now it is time to test our DSL editor. To do so do the following:
- Create a new Project “MyDSLTest”
- In the Project Explorer right-click on the project and select Configure / Add Xtext Nature
- Create a new file “test.mydsl”.
- Enter “Hello Xtext!”. The word “Hello” should be colored purple and the Outline view should contain “Xtext”
9. Creating an executable application
Once the product has been tested successfully you can export it with the Eclipse Product export wizard. There is a direct link to it on the Overview page of the MyDSL.product file or run the Export wizard through File / Export / Plug-in Development / Eclipse product.
Now you have a small decent IDE that contains an editor for your DSL! Of course, depending on the requirements, you need to add more.
- If your DSL requires more features to run add them to the feature.xml of org.xtext.example.mydsl.platform.feature
- You might generate code for your DSL models. You should read about Xtext Build Participants. The Xtext Domainmodel example, which can be created with the New Project Wizard, demonstrates this also.
- Add further IDE features (SVN, …) for your product to the Feature dependencies of the Product Configuration.
- Set up a headless build for your product. Consider to use Maven 3 / Tycho for this.