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

Parametrized java home #816

Closed
cquiroz opened this issue Jun 20, 2016 · 4 comments
Closed

Parametrized java home #816

cquiroz opened this issue Jun 20, 2016 · 4 comments
Labels
universal Zip, tar.gz, tgz and bash issues

Comments

@cquiroz
Copy link
Contributor

cquiroz commented Jun 20, 2016

I want to make my packages (tarball and rpm) include the jre. I have managed to include the jre but I cannot make the -java-home parameter work correctly. I'd like to do something like

-java-home ${app_home}/../jre

but the bash script doesn't support recursive variable expansion. Specifically this line

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

Ideally $2 could be eval before running. I changed the script to this and it works but I cannot claim it is the best way to do it

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

Is there another way to go?

@muuki88
Copy link
Contributor

muuki88 commented Jun 20, 2016

If you want to package the jre, I would recommend using the JdkPackagerPlugin. It requires java 8 on your build system, but you can easily include the jre.

Regarding your bash script additions: I'm really not an expert considering bash. In my personal experience it's always a good idea to keep that bash magic as small possible.

@cquiroz
Copy link
Contributor Author

cquiroz commented Jun 20, 2016

I'd like to produce a tarball and rpm containing the jre, it seems neither option is very well supported by JdkPackagerPlugin hence the modification of the launch script

I can fix this by doing my own bash launcher template but this maybe useful more generally

@muuki88
Copy link
Contributor

muuki88 commented Jun 20, 2016

Can you post your complete build configuration that is necessary to achieve this? The how to do this is definitely useful.

@cquiroz
Copy link
Contributor Author

cquiroz commented Jun 21, 2016

This is a condensed version of my build configuration

  lazy val app_server = project.in(file("app/server"))
    .enablePlugins(JavaServerAppPackaging)
    .settings(
      // Main class for launching
      mainClass in Compile := Some("MainClass"),
      // Name of the launch script
      executableScriptName := "server",
      // No javadocs
      mappings in (Compile, packageDoc) := Seq(),
      // Don't create launchers for Windows
      makeBatScript := None,
      // Specify a different name for the config file
      bashScriptConfigLocation := Some("${app_home}/../conf/launcher.args"),
      // Launch options
      javaOptions in Universal ++= Seq(
        // -J params will be added as jvm parameters
        "-J-Xmx512m",
        "-J-Xms256m",

        "-java-home ${app_home}/../jre"
      ),

      // Put the jar files in the lib dir
      mappings in Universal <+= (packageBin in Compile) map { jar =>
        jar -> ("lib/" + jar.getName)
      },

      // Put the jre in the tarball
      mappings in Universal ++= {
        val jresDir = (ocsJreDir in ThisBuild).value
        // Map the location of jre files
        val jreLink = "JRE64_1.8"
        val linux64Jre = jresDir.toPath.resolve("linux").resolve(jreLink)
        directory(linux64Jre.toFile).map { j =>
          j._1 -> j._2.replace(jreLink, "jre")
        }
      }      
    )

The -java-home option requires the fix on the launcher to replace the ${app_home} variable

@muuki88 muuki88 added the universal Zip, tar.gz, tgz and bash issues label Jun 21, 2016
@muuki88 muuki88 closed this as completed Jul 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
universal Zip, tar.gz, tgz and bash issues
Projects
None yet
Development

No branches or pull requests

2 participants