-
Notifications
You must be signed in to change notification settings - Fork 1
/
run
executable file
·41 lines (30 loc) · 1.43 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh
# To run our code, we must have it in our classpath.
# We use $(ls target/*.jar) instead of target/stars-1.0.jar so that
# this script can be reused in other projects more easily.
TARGET=$(ls target/*.jar 2>/dev/null)
if [ -z "$TARGET" ]; then
echo "No jar file in target/, try 'mvn package'".
exit 1
fi
# In the pom.xml, we've already explained other what libraries we
# depend on. Maven downloaded them, and put them "somewhere" (our
# repository). Now we ask maven to build up the CLASSPATH that let us
# run against those libraries.
# First, we put the CLASSPATH in .classpath if the pom.xml is newer
# than out existing .classpath file. (We avoid this command if
# .classpath is fresh, since it's rather slow.)
if [ ! .mvn-classpath -nt pom.xml ]; then
mvn dependency:build-classpath -Dmdep.outputFile=.mvn-classpath -q
fi
# Now, we set $CP to the contents of the .classpath file.
CP=$(cat .mvn-classpath)
# Again, we're trying to make the script more reusable by guessing the
# package name from the current directory, instead of hard coding.
# But this relies on some conventions in naming. You'll have to call
# your class "Main" and use our recommended package structure.
PROJECT=$(basename $(pwd))
# The funny symbol: "$@" passes the command-line arguments on from
# this script to your Java program.
trap "rm -rf /ltmp/$USER; exit 255;" SIGINT SIGKILL SIGTERM
java -cp $TARGET:$CP threadinglab.primes.PrimesMain "$@"