Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Compile and package a scala code to a single jar. Also includes dependencies for json4s that can be omitted.
<?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.wm</groupId>
<artifactId>wmLogger</artifactId>
<version>1.0-SNAPSHOT</version>
<name>${project.artifactId}-${project.version}</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<scala.version>2.10.3</scala.version>
<!--<scala.version>2.11.0-RC3</scala.version>-->
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.json4s</groupId>
<!--<artifactId>json4s-native_${scala.version}</artifactId>-->
<artifactId>json4s-native_2.10</artifactId>
<version>3.2.7</version>
</dependency>
<dependency>
<groupId>org.json4s</groupId>
<!--<artifactId>json4s-jackson_${scala.version}</artifactId>-->
<artifactId>json4s-jackson_2.10</artifactId>
<version>3.2.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.1.6</version>
<executions>
<execution>
<id>scala-compile</id>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<!--<arg>-make:transitive</arg>-->
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
<!--Packaging-->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.wm.logger.WMLoggerTest</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@davidraviv

This comment has been minimized.

Copy link
Owner Author

@davidraviv davidraviv commented Mar 27, 2014

To compile:

mvn compile

To package (buile the jar):

mvn package

To execute the jar:

cd target
java -jar wmLogger-1.0-SNAPSHOT-jar-with-dependencies.jar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment