Pergunta

I need to generate java code from jet templates using a maven project and it should be done outside eclipse environment, but so far i haven't figure out how to do this.

I'm using maven 3x and jet 1.1.x.

I've tried several approaches but none of them seems to work:

  • invoke library org.eclipse.emf.codegen.jet.JETCompiler. This library seems to have a strong dependency with eclipse's environment and for such reason it failed.
  • one of maven's jet plugin doesn't work neither and i'm using the same example as provided in the offical website ([tikal-maven-jet-plugin][1]), here's how it looks like:

    http://network.tikalk.com/release/tikal-maven-jet-plugin/usage.html

Does anyone have an idea how to do this?

Thanks a lot, Carlos

Foi útil?

Solução

Because of the way JET works, it'll only actually be runnable inside an eclipse environment. However, it's actually possible to launch eclipse headlessly to run an ant build script, so you get the eclipse parts you need running, without the UI. In order to do this, you need to launch the org.eclipse.ant.core.antRunner application. There's some documentation on how to do that here: http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2FantRunner.htm

Once you've launched the antRunner application, you can use the JET ant tasks to compile your templates and run your transform: http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.jet.doc%2Freferences%2Fant%2FantTasks.xhtml

There are some important caveats about headless template compilation which are relevant if you're headlessly compiling eclipse plugins, documented here: http://wiki.eclipse.org/JET_FAQ_How_to_I_compile_JET_templates_in_a_headless_build

I'm not sure how well any of this integrated with Maven, but this seems to be the best approach from ant. If you're wanting to run a transform from Java, there's some information here: http://wiki.eclipse.org/JET_FAQ_How_do_I_run_a_JET_transformation_from_Java%3F. You will still need to be in an eclipse environment for it to work though.

Outras dicas

The tikal-maven-jet-plugin worked for me.

Here's a sample of a JET file I used in src/main/templates/generator.jet, I don't use the EMF classes, just standard Map.

<%@ jet class="TableModelGenerator" package="net.trajano.framework.tool" %>
<% java.util.Map meta = (java.util.Map)argument; %> 
package <%=meta.get("PackageName")%>;
public class <%=meta.get("ClassName")%> {
}

The plugin configuration I used is

<plugin>
    <groupId>com.tikal</groupId>
    <artifactId>tikal-maven-jet-plugin</artifactId>
    <version>0.4.0</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <includeTemplates>
            <include>**/*.jet</include>
        </includeTemplates>
    </configuration>
</plugin>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top