diff options
| author | Julia McCauley <skurvyj@gmail.com> | 2021-03-30 21:22:31 -0400 |
|---|---|---|
| committer | Julia McCauley <skurvyj@gmail.com> | 2021-03-30 21:22:31 -0400 |
| commit | bfd8782e5b028dc47655eb332b43cbde7697bfda (patch) | |
| tree | 046b8e06f7f4b530f7fb35323d055912332b1110 /run | |
| parent | afccf15fe466259234a132b7cd925299871fd5e7 (diff) | |
set up project structure
Diffstat (limited to 'run')
| -rwxr-xr-x | run | 49 |
1 files changed, 49 insertions, 0 deletions
@@ -0,0 +1,49 @@ +#!/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) + +# We're trying to make the script more reusable by finding the package +# name, 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. + +# Find Main.java. It should be in a package below your username package. +MAIN=$(ls src/main/java/edu/brown/cs/*/*/Main.java) +[ -z "$MAIN" ] && echo "You need a Main.java" && exit 1 +[ ! -e "$MAIN" ] && echo "You can only have one Main.java" && exit 1 +STUDENT=$(basename $(dirname $(dirname $MAIN))) +MAINPKG=$(basename $(dirname $MAIN)) + +# No guarantees yet, but we're trying to support Windows, which uses a +# different Path Separator in classpaths. +PATHSEP=":" +if [ "$OSTYPE" = 'cygwin' -o "$OSTYPE" = 'msys' ]; then + PATHSEP=";" +fi + +# The symbol "$@" passes the command-line arguments from +# this script to your Java program. +java -ea -cp "$TARGET$PATHSEP$CP" edu.brown.cs.$STUDENT.$MAINPKG.Main "$@" |
