JET stands for Java Emitter Templates that is based entirely in Eclipse. It is meant to be run with workspaces. This example .javajet is what a JET template can look like (from EMF).

Some more articles:

  1. Setting up an EMF/JET testing project with JUnit and Eclipse

Creating a JET code generation plugin for an EMF model

JET transforms are stored as Eclipse plugin projects, so you need to make a new plugin project first.

  1. Select New > EMFT JET Transformation Project.
  2. This project will automatically add some basic templates (dump.jet) and plugin.xml.
  3. To plugin.xml, add:
<plugin>
   <extension
         id=""
         name=""
         point="org.eclipse.jet.transform">
      <transform
            modelExtension="model"
            modelLoader="org.eclipse.jet.emf"
            startTemplate="templates/main.jet"
            templateLoaderClass="org.eclipse.jet.compiled._jet_transformation">
         <description></description>
         <tagLibraries>
            <importLibrary id="org.eclipse.jet.controlTags" usePrefix="c" autoImport="true"/>
            <importLibrary id="org.eclipse.jet.javaTags" usePrefix="java" autoImport="true"/>
            <importLibrary id="org.eclipse.jet.formatTags" usePrefix="f" autoImport="true"/>
            <importLibrary id="org.eclipse.jet.workspaceTags" usePrefix="ws" autoImport="false"/>
         </tagLibraries>
      </transform>
   </extension>
</plugin>
  1. This will add the imported libraries. Most importantly is that you set modelExtension to the extension of your EMF models, and modelLoader to the EMF loader – org.eclipse.jet.emf.

The rest of these instructions are for making a contribution to Eclipse to add a Right Click menu to files in order to generate code.

  1. Create a new project (or edit the existing project).
  2. Add the org.eclipse.jet dependency to required plug-ins.
  3. Add to the org.eclipse.ui.popupMenus extension point (in plugin.xml) a menu item that points to a IViewActionDelegate.
  4. Use the following code to call a JET template programatically:
private IStatus generateCodeFrom(IFile o, IAction action, IProgressMonitor monitor) {
  if (o.getFileExtension().equals("model")) {
    Map<String,Object> variables = new HashMap<String,Object>();
    variables.put("somevar", "a variable");
    return JET2Platform.runTransformOnResource("org.openiaml.test.uml3.generate.ejet", o, variables, monitor);
  }

  return null;
}

The full implementation of this can be accessed on SVN:

  1. http://iaml.svn.sourceforge.net/viewvc/iaml/trunk/examples/jet/GenerateCodeAction.java?view=markup (Java)
  2. http://iaml.svn.sourceforge.net/viewvc/iaml/trunk/examples/jet/plugin.xml?view=markup (plugin.xml)

(See more code examples at GMF Code Samples.)

Could not load JET template loader

Look at your Error Log in Eclipse to try and find out what the problem is. If you don’t get any error logs, you can start a new workspace in debug mode, and debug from there. The line you are looking for is org.eclipse.jet.internal.runtime.JETBundleManager.getTemplateLoader(java.lang.String) line: 454

For example, I got this exception stack trace: java.lang.ClassNotFoundException: Cannot load "org.eclipse.jet.compiled._jet_transformation" because the bundle "file:C:/Documents and Settings/Jevon/runtime-uml3debug/org.openiaml.test.uml3.generate.ejet" cannot be resolved.

Which I then found out, that by looking at my development environment, I was getting these errors:

Could not find matching bundle for Require-Bundle: org.eclipse.core.runtime; bundle-version="[3.4.0,4.0.0)"
Could not find matching bundle for Require-Bundle: org.eclipse.emf.edit.ui; bundle-version="[2.4.0,3.0.0)"
...

Since I am running Eclipse 3.3, it means that JET is looking for the wrong version of the Eclipse plugin.