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

Expand the java home argument #822

Merged
merged 3 commits into from
Jun 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ process_args () {

-main) custom_mainclass="$2" && shift 2 ;;

-java-home) require_arg path "$1" "$2" && java_cmd="$2/bin/java" && shift 2 ;;
-java-home) require_arg path "$1" "$2" && jre=`eval echo $2` && java_cmd="$jre/bin/java" && shift 2 ;;

-D*|-agentlib*) addJava "$1" && shift ;;
-J*) addJava "${1:2}" && shift ;;
Expand Down
19 changes: 19 additions & 0 deletions src/sbt-test/bash/java-home-var-expansion/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
enablePlugins(JavaAppPackaging)

name := "java-home-override"

version := "0.1.0"

javaOptions in Universal ++= Seq(
"-java-home ${app_home}/../jre"
)

TaskKey[Unit]("run-check") := {
val cwd = (stagingDirectory in Universal).value
// Don't check for java but it will fail since the jre is not in place
val cmd = Seq((cwd / "bin" / packageName.value).getAbsolutePath, "-v", "-no-version-check")
val output = Process(cmd, cwd).lines_!
val outStr = output.mkString("\n")
// Check that ${app_home} has been substitued
assert(outStr.contains("stage/bin/../jre/bin/java"), "Output didn't contain success: " + output)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object MainApp extends App {
println("SUCCESS!")
}
3 changes: 3 additions & 0 deletions src/sbt-test/bash/java-home-var-expansion/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Run the staging and check the script.
> stage
> run-check
4 changes: 4 additions & 0 deletions src/sphinx/archetypes/java_app/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ The start script provides a few standard options you can pass:
``-jvm-debug <port>``
Turn on JVM debugging, open at the given port

``-java-home <java home>``
Override the default JVM home, it accept variable expansions, e.g.
``-java-home ${app_home}/../jre``

``-main``
Define a custom main class

Expand Down
48 changes: 48 additions & 0 deletions src/sphinx/recipes/embedded-jvm.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Embedding JVM in Universal
==========================

Sbt Native Packager supports embedding the jvm using the :ref:`jdkpackager-plugin`,
however, in some cases you may want instead to embed the JVM/JRE in other formats,
e.g. a tarball with one of the java archetypes.

To accomplish this you need to:

* Add the JVM/JRE of your choice to the `mappings`
* Make the launcher use the embedded `jre`

Adding the JVM
--------------

The JRE is by definition OS dependent, hence you must choose the one appropriate
for your case. The example below assumes a Linux 64 JRE, whose files are at
``$HOME/.jre/linux64``. The files will be copied to a ``jre`` directory in your
distribution

.. code-block:: scala

import NativePackagerHelper._

...

mappings in Universal ++= {
val jresDir = Path.userHome / ".jre"
val linux64Jre = jresDir.toPath.resolve("linux64")
directory(linux64Jre.toFile).map { j =>
j._1 -> j._2.replace(jreLink, "jre")
}
}

Application Configuration
-------------------------

In order to run your application in production you also need to make the launcher
use the jre added above. This can be done using the ``-java-home`` option with a
relative path.

.. code-block:: scala

javaOptions in Universal ++= Seq(
// Your original options

"-java-home ${app_home}/../jre"
)
3 changes: 1 addition & 2 deletions src/sphinx/recipes/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ This section provides recipes for common configurations. If you can't find what
deployment
scalajs
package_configuration


embedded-jvm

.. _sbt-native-packager examples: https://github.com/muuki88/sbt-native-packager-examples