Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

packBashTemplate not actually implemented #254

Open
carueda opened this issue Sep 8, 2021 · 2 comments
Open

packBashTemplate not actually implemented #254

carueda opened this issue Sep 8, 2021 · 2 comments

Comments

@carueda
Copy link

carueda commented Sep 8, 2021

First off, thanks for this great tool.

I would like to generate a simplified launcher script (for example, not relying on javac to determine JAVA_HOME, and other unneeded stuff in my case). In the release notes I found the option packBashTemplate, which looked like exactly what I needed to accomplish that goal. Unfortunately, it seems this is not actually implemented.

Maybe I'm missing something. Thanks.

@ShashankReddy1804
Copy link

Hi carueda. Did you find any alternate for this, I was working on one of the migration project in older version I had packBashTemplate (sbt-pack, 0.7.4), now I need atleast (sbt-pack, 0.9.0)

@carueda
Copy link
Author

carueda commented Jun 24, 2024

Hi!

Unfortunately, the project related with this is not open source (otherwise I would point you to it), but, basically:

I created a task createDistribution dependent on pack:

val createDistribution = taskKey[Unit]("create java based distribution")

...

    packMain := Map("myapp" -> "org.example.foo.Main"),
    createDistribution := {
      val _ = pack.value
      import scala.sys.process._
      println(s"Creating java based distribution $myAppVersion ...")
      s"bin/distribution/create.sh $myAppVersion".!
    },

where create.sh, working on the result of sbt pack, incorporates a simplified launcher script

set -ue

VERSION=$1

DIST_NAME="myapp-$VERSION"
mkdir -p out
OUT_DIR="$(pwd)/out"
OUT_ZIP="$OUT_DIR/${DIST_NAME}.zip"

BASE_DIR="main/target/pack"
RENAMED_DIR="main/target/${DIST_NAME}"

rm -rf "${RENAMED_DIR}"
mv "${BASE_DIR}" "${RENAMED_DIR}"
printf "Overwriting launcher script...\n"
cp bin/distribution/myapp_launcher.sh "$RENAMED_DIR/bin/myapp"

printf "Zipping...\n"
rm -f "$OUT_ZIP"
(cd main/target && zip -r "$OUT_ZIP" "$DIST_NAME")

printf "Done: %s\n" "$OUT_ZIP"

Adjust settings as appropriate and of course include a launcher script per your needs, using the one used by pack as a basis. Hope that helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants