Free tutorials for Java, Eclipse and Web programming



Follow me on twitter

Java Emitter Template (JET) - Tutorial

Lars Vogel

Version 0.4

01.02.2011

Revision History
Revision 0.1 02.08.2009Lars Vogel
created
Revision 0.2 - 0.402.12.2009 - 01.02.2011Lars Vogel
bug fixing and enhancements

Eclipse JET

This article describes the usage of Eclipse JET to transform Eclipse EMF models into other output. This article is based on Eclipse 3.6 (Helios).


Table of Contents

1. Java Emitter Template (JET)
1.1. Overview
1.2. Prerequisites
2. Installation
3. Create your Jet Project
3.1. Convert project
3.2. JET template editor
3.3. JET directive
3.4. Usage of JET
3.5. Include
4. Thank you
5. Questions and Discussion
6. Links and Literature
6.1. Source Code
6.2. JET Resources
6.3. vogella Resources

1. Java Emitter Template (JET)

1.1. Overview

JET is a "model to text" engine which allows to generate (text) output based on an EMF model. For example you can generate SQL, Java, XML, Text, HTML, etc. JET uses a template technology which is very closely related to the Syntax of Java Server Pages (JSPs).

In JET you define templates. These templates will be used to create Java Implementation classes. This process step is called "translation". .

The Java classes can then be used to create the final output, e.g. a HTML file. This generated class can be initialized and will create the desired result as a String with the method "generate()". This process step is called "generation".

JET has three different types of expressions, e.g. directives, expressions and scriplets. Scriplets are started with <% and ended with %> and can contain any java code. Expressions allow to insert string values within the JET output and the directives defines the settings for the JET template.

The JET compiler creates a Java source file for each JET. The suggestion for the JET templates is to use the following naming schema: ClassName.outputsuffixjet, whereby the outputsuffix determins the output, e.g. java for Java Source or html for HTML files.

1.2. Prerequisites

The following will use the webpage example created in Eclipse EMF Tutorial . Please make sure you have create the EMF model described in this article.