How To Guide
From Skyway Wiki
Contents |
Create a JET Project
You don't have to use JET to generate your artifacts (source files, configuration files, etc). However, we've used JET for all of our core templates so these instructions assume you are using JET as well.
- Create an EMFT JET Transformation Project call ReplaceArtifact. This is an Eclipse plug-in project that supports JET template development.
- Open plugin.xml.
- Click the Dependencies tab. Add these dependencies to your project (these represent a common set of dependencies you will likely need):
- org.eclipse.jet
- org.skyway.core
- org.eclipse.core.runtime
- org.skyway.integration.java
- org.eclipse.emf.ecore
- org.skyway.integration.java.spring
- Click the Extensions tab. Expand the org.eclipse.jet.transform extension (this was added automatically when you created your EMFT JET Transformation Project). Expand the (transform) and (tagLibraries) nodes. Add the following two tag libraries:
- id:org.skyway.integration.java.skywayCodeGenTags, usePrefix:sw, autoImport:true
- id:org.skyway.integration.data.persistence.skywayPersistenceTags, usePrefix:persistence, autoImport:true
Create a New Template
- Right click on the /templates folder and select New and File.
- Type Exception.jet into the File name field and click Finish.
- Paste the following code into the file and save.
<%@ jet
package="org.skyway.deploy.templates"
class="NewExceptionTemplate"
%>
<%@taglib id="org.eclipse.jet.javaTags" prefix="java"%>
<%@taglib prefix="ws" id="org.eclipse.jet.workspaceTags"%>
<%@taglib prefix="c" id="org.eclipse.jet.controlTags"%>
<%@taglib prefix="sw" id="org.skyway.integration.java.skywayCodeGenTags"%>
package <sw:package select="$model" var="pkg"/>;
<sw:javaType select="$model" package="true" var="fullyQualifiedClassName" emit="false"/>
<java:importsLocation package="{$pkg}"/>
<java:impliedImport name="{$fullyQualifiedClassName}"/>
/**
* THIS IS MY OVERRIDDEN TEMPLATE!
* <sw:documentation select="$model" />
* @generated
*/
public class <sw:javaType select="$model" /> extends <java:import>org.skyway.execution.exception.SkywayException</java:import> {
private static final long serialVersionUID = 1L;
/**
* Default Constructor
* @generated
*/
public <sw:javaType select="$model" /> () {
super();
}
/**
* Constructor taking message
* @generated
*/
public <sw:javaType select="$model" /> (String message) {
super (message);
}
/**
* Constructor taking root cause
* @generated
*/
public <sw:javaType select="$model" /> (Throwable t) {
super (t);
}
/**
* Constructor taking message and root cause
* @generated
*/
public <sw:javaType select="$model" /> (String message, Throwable t) {
super (message, t);
}
}
Replace the Old Template with the New Template
- Open plugin.xml (if not already open).
- Click the Extensions tab.
- Click the Add button.
- Type jetArtifactDefinitionSet into the Extension Point filter field.
- Select the org.skyway.core.jetArtifactDefinitionSet extension point and click Finish.
- It should have added and selected a node for you. The node will have a name like ReplaceArtifact.set2 (set).
- Enter org.skyway.integration.java.spring.artifactset into the id field. This is the id of the core Skyway artifact set that you are modifying.
- Enter a 1 into the priority field. The priority of all core artifacts is 0, so anything greater than 0 will take precedence.
- Click back on the ReplaceArtifact.set2 (set) node and you should notice it now has a different name based on what you typed into the id field.
- Right click this node and select New and override.
- It should have added and selected a node for you. The node will have a name like ReplaceArtifact.jetArtifactDefinition2 (jetArtifactDefinition).
- Click the Browse button next to the template field and select the Exception.jet template that you just created.
- Enter org.skyway.core.generation.java.JavaArtifactDefinition into the type field. This is the name of a class that implements IArtifactDefinition. JavaArtifactDefinition is a generic super class that defines how to generate a Java class.
- Leave the destination field blank.
- Click back on the ReplaceArtifact.jetArtifactDefinition2 (jetArtifactDefinition) node and you should notice it now has a different name based on what you typed into the template field.
- Now click on its parent node. It should have a name like ReplaceArtifact.override3 (override).
- Enter templates/Exception.jet into the originalTemplate field. This is the template that we are overriding.
- Save your changes to plugin.xml.
Launch a New Workspace With Your Changes
- Open the Run Dialog.
- Right click Eclipse Application and select New.
- On the Main tab under Program to Run select the Run a product radio and select the org.skyway.visualperspectives.product product.
- Create a new Skyway Project called MyProject.
- Add a Web Controller called MyController to this project.
- Add an Exception called MyException to this controller.
- Type Ctrl-Shift-T to open the Eclipse type chooser.
- Type MyException and select the MyException class.
- You should notice that the exception class was built using your template.

