Invoke headless code generation with Maven.
Maven allows you to automatically build and deploy your Java projects. Its operation is mainly revolving around the so-called “build lifecycle” and a number of plugins. One of them is the exec-maven-plugin, which allows the user to execute arbitrary tools.
The Greeter-class imports the statemachine sources and adds “Hello World!” to a string everytime the statemachine cycles until it is finalized. For Maven, instead of a Makefile, there is the pom.xml file.
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.springframework</groupId> <artifactId>gs-maven</artifactId> <packaging>jar</packaging> <version>0.1.0</version> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.1</version> <executions> <execution> <id>Generate</id> <phase>generate-resources</phase> <goals> <goal>exec</goal> </goals> </execution> </executions> <configuration> <executable>scc</executable> </configuration> </plugin> </plugins> </build></project>
As you can see, it is pretty big. If you have never worked with Maven before, you will likely be overwhelmed. The interesting part is the plugin in the bottom, it specifies which plugin will be used and what it should do – namely, execute scc. Another interesting detail is the binding to a phase inside of the execution block: Maven executes generate-resources before the compile phase, thus the needed sources will be there when we need them.