Permalink
Find file
d1bd1b9 Jan 22, 2017
62 lines (52 sloc) 2.04 KB
@description "teaches a maven project how to make an executablejar"
@tag "maven"
editor MakeExecutableJar
@displayName "Main Class"
@description "Fully qualified Java classname"
@minLength 1
@maxLength 100
param main_class: @java_package
let pluginContents = """<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<outputFile>target/executable.jar</outputFile>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>__I_AM_THE_MAIN__</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>"""
let runScript = """#!/bin/bash
# http://stackoverflow.com/questions/59895/getting-the-source-directory-of-a-bash-script-from-within
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
java -jar $DIR/../target/executable.jar "$@"
"""
with Pom p
do addOrReplaceBuildPlugin "org.apache.maven.plugins" "maven-shade-plugin" pluginContents
with File f when path = "pom.xml" begin
do replace "__I_AM_THE_MAIN__" main_class
do eval { print("run `mvn package` to create an executable jar")}
end
with Project p begin
do eval { print("Find a run script in your project's bin directory. You'll have to make it executable yourself, sorry") }
do addFile "bin/run" runScript
end