Package and distribute a Scala jar to run on the command line

Add this to pom.xml – (update the mainClass to match your program):

<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.1.2</version>
    <configuration>
        <archive>
            <manifest>
                <mainClass>com.myCorp.testJar.App</mainClass>
                <addClasspath>true</addClasspath>
                <classpathLayoutType>custom</classpathLayoutType>
                <customClasspathLayout>lib/${artifact.artifactId}-${artifact.version}${dashClassifier?}.${artifact.extension}
                </customClasspathLayout>
            </manifest>
        </archive>
    </configuration>
</plugin>
<plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>3.1.1</version>
    <configuration>
        <outputDirectory>${project.build.directory}/lib</outputDirectory>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
        </execution>
    </executions>
</plugin>

In Eclipse right click project and run as Maven build with goal=package

Sample output for a project in D:\06repo Eclipse workspace:
Building jar: D:\06repo\testJar\target\testJar-0.0.1-SNAPSHOT.jar
Creates lib directory under testJar\target directory.

Execute the jar file.

D:\06repo\testJar\target>java -jar testJar-0.0.1-SNAPSHOT.jar

Hello World!

Zip the jar file along with the lib directory.

D:\06repo\testJar\target>f:\7-Zip\7z a -tzip testJar.zip testJar-0.0.1-SNAPSHOT.jar lib
Copy the zip file to a client that has Java installed.

D:\06repo\testJar\target>cp testJar.zip d:/tmp

Extract the zip file in the new client location.
d:\tmp>f:\7-Zip\7z x testJar.zip
Run the jar file in the new client location.

d:\tmp>java -jar testJar-0.0.1-SNAPSHOT.jar

Hello World!

Stack Overflow Article: https://stackoverflow.com/questions/6758258/running-a-maven-scala-project