Skip to content

Jar Runner

Alex Vigdor edited this page Mar 1, 2019 · 10 revisions

groovity-jar-runner

Groovity servlet is designed to allow you to easily package standard java WAR files for deployment in an external servlet container such as Tomcat or Jetty. However, you may also choose to package your application as a standalone executable jar file with an embedded jetty server; this embedded server is configured identically to the embedded server used by the groovity-maven-plugin and groovity-standalone, and supports all the features of groovity-servlet.

To leverage groovity-jar-runner, you would set your application to use jar packaging and import groovity-jar-runner as a dependency; you must also configure the maven shade plugin to pull the pieces together into an executable jar. Here is a sample maven pom that you can start from. You can add additional groovity modules as dependencies to leverage them, for example groovity-data or groovity-events, as well as any other application dependencies you might have.

<?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>com.mycompany</groupId>
  <artifactId>my-app</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>Groovity jar runner app</name>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <groovity.version>2.0.4</groovity.version>
  </properties>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
              <mainClass>com.disney.groovity.jarrunner.GroovityJarRunner</mainClass>
            </transformer>
            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
              <resource>groovity/manifest</resource>
            </transformer>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
          </transformers>
        </configuration>
      </plugin>
      <plugin>
        <groupId>com.disney.groovity</groupId>
        <artifactId>groovity-maven-plugin</artifactId>
        <version>${groovity.version}</version>
        <executions>
          <execution>
            <id>groovityTest</id>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
          <execution>
            <id>groovityPackage</id>
            <goals>
              <goal>package</goal>
            </goals>
          </execution>
          <execution>
            <id>default-cli</id>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>com.disney.groovity</groupId>
      <artifactId>groovity-jar-runner</artifactId>
      <version>${groovity.version}</version>
    </dependency>
  </dependencies>
</project>