-
Notifications
You must be signed in to change notification settings - Fork 4
library maven project setup
This section describes how to set up a project using Apache Maven as a build tool.
Java 8 and maven should be installed in the system and properly configured.
Epigraph should be available from the maven repositories. You can install it locally to achieve this:
git clone [email protected]:SumoLogic/epigraph.git
cd epigraph
mvn install
Install Epigraph IDEA plugin if you're using IntelliJ, it is available from the project github page.
Source code for this example is in the examples/library
folder, in
order to build and run it:
cd examples/library
mvn install
mvn -pl library-service exec:java
Project consists of two modules:
-
library-schema
contains Epigraph schema definition: language-agnostic data structures declarations and service APIs. This module is used bylibrary-service
to generate implementation bindings and should also be distributed to the clients for client bindings generation -
library-service
contains generated Java bindings and service implementation code plus a main class which starts Undertow server with Epigraph handler.
Parent pom.xml
file has a few important things. First is a list of modules
in the project:
<modules>
<module>library-schema</module>
<module>library-service</module>
</modules>
Then there are some properties which tell Maven to use Java 8 and UTF-8:
<properties>
<!-- Java 8 required -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Finally, <build><pluginManagement><plugins>
section contains Epigraph
plugins that will be used by the modules:
<plugin>
<groupId>ws.epigraph</groupId>
<artifactId>epigraph-maven-plugin</artifactId>
<version>0.0.2-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>ws.epigraph</groupId>
<artifactId>epigraph-java-maven-plugin</artifactId>
<version>0.0.2-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>generate-sources</goal>
</goals>
</execution>
</executions>
</plugin>
epigraph-maven-plugin
compiles schema files validating them for
errors and packages them in a jar
artifact for publishing and
distribution
epigraph-java-maven-plugin
generates Java bindings
library-schema
pom sets artifact ID to be examples-library-schema
to keep naming scheme used by other examples:
<artifactId>examples-library-schema</artifactId>
Then it declares a dependency on Epigrph built-in types
<dependencies>
<dependency>
<groupId>ws.epigraph</groupId>
<artifactId>epigraph-builtin-types-schema</artifactId>
<version>0.0.2-SNAPSHOT</version>
</dependency>
</dependencies>
In build
section redefines source folder locations to be more Epigraph friendly
<sourceDirectory>${project.basedir}/src/main/epigraph</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/epigraph</testSourceDirectory>
And tells Maven to use epigraph-maven-plugin
<plugins>
<plugin>
<groupId>ws.epigraph</groupId>
<artifactId>epigraph-maven-plugin</artifactId>
</plugin>
</plugins>
library-service
pom sets artifact ID to be examples-library-service
<artifactId>examples-library-service</artifactId>
Then it defines some dependencies. First one is on library-schema
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>examples-library-schema</artifactId>
<version>${project.parent.version}</version>
</dependency>
Second one is on Epigraph Undertow-based server implementation
<dependency>
<groupId>ws.epigraph</groupId>
<artifactId>epigraph-java-http-server-undertow</artifactId>
<version>0.0.2-SNAPSHOT</version>
</dependency>
And a simple backend for SLF4J logging.
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.22</version>
</dependency>
Finally plugins section includes epigraph-java-maven
plugin
plus exec-maven-plugin
so we can easily run the service:
<plugins>
<plugin>
<groupId>ws.epigraph</groupId>
<artifactId>epigraph-java-maven-plugin</artifactId>
<configuration><server/></configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>ws.epigraph.examples.library.LibraryServer</mainClass>
</configuration>
</plugin>
</plugins>
Epigraph plugin configuration includes an empty <server/>
tag which tells to generate implementation stubs for all
services.
Next section: schema module