Building a Jar for Deployment on a Compute Server - Horsmann/FlexTag GitHub Wiki
To package a project as self-contained executable .jar file we use the Maven shade-plugin
. The use of the plugin is quite easy. Take below code snippet which is to be placed within the <build>..</build>
segment to prepare your project.
The most information in this code block is not of importance to you - only the line mentioning the main class
is i.e. <mainClass>de.unidue.ltl.useFlexTag.ExampleXYZ</mainClass>'. Here you have to provide the full package path to the class containing the
main()of your project. In our case this is the class
ExampleXYZin the package
de.unidue.ltl.useFlexTag`
To build the jar execute mvn clean install
. The resulting jar file de.unidue.ltl.useFlexTag-0.0.1-SNAPSHOT-standalone
can be found in the target
folder.
To execute the jar file type and assign the execution 16GB of Ram (-Xmx flag) type:
java -Xmx16g -jar de.unidue.ltl.useFlex-0.0.1-SNAPSHOT-standalone <param1> <param2> <paramN>
Please note that when building a shaded-jar hard-wired file path in the program code such as src/main/resource/data.txt
are no longer valid. Such paths must be provided as parameters or loaded from an external configuration file (which as to be provided as parameter).
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<!-- Set the main class of the executable JAR -->
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>de.unidue.ltl.useFlex.ExampleXYZ</mainClass>
</transformer>
<!-- Merge the uimaFIT configuration files -->
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>
META-INF/org.apache.uima.fit/fsindexes.txt
</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>
META-INF/org.apache.uima.fit/types.txt
</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>
META-INF/org.apache.uima.fit/typepriorities.txt
</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>
META-INF/lab/engines.properties
</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
<resource>
META-INF/spring/activemq-broker.xml
</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
<!-- Prevent huge shaded artifacts from being deployed to a Maven
repository (remove if not desired) -->
</transformers>
<outputFile>
${project.build.directory}/${project.artifactId}-${project.version}-standalone.jar
</outputFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>