question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Specifying -java-home at command line works in some cases, but not in all.

See original GitHub issue

SBT is awesome, but I seem to have to change my path to point to my preferred JDK in some cases.

Desired behavior SBT uses -java-home if specified

Actual behavior Specifying -java-home works in some cases, but not in all.

Evidence

me@myComputer:~/Documents/someCo/applications/code/myApp/WEB-INF$ $SBT_HOME/bin/sbt -java-home /usr/lib/jvm/latest-oracle-jdk Loading /home/me/tools/sbt-0.13/bin/sbt-launch-lib.bash [info] Set current project to MyAwesomeAppTest (in build file:/home/me/Documents/someCo/applications/code/myApp/WEB-INF/) test

Testing…

That worked as expected. Then I made the following change to my build.sbt file (commented out 2 lines, added 2 new lines):

//unmanagedJars in Compile ++= // Attributed.blankSeq((file(“/home/me/Documents/someCo/applications/code/myApp/WEB-INF/src/test/lib/”) * “*.jar”).get)

libraryDependencies += “org.scalatest” % “scalatest_2.10” % “1.9.1”

libraryDependencies += “junit” % “junit” % “4.10”`

Now there is a problem:

$SBT_HOME/bin/sbt -java-home /usr/lib/jvm/latest-oracle-jdk Loading /home/me/tools/sbt-0.13/bin/sbt-launch-lib.bash [info] Set current project to MyAwesomeAppTest (in build file:/home/me/Documents/someCo/applications/code/myApp/WEB-INF/) test [info] Updating {file:/home/me/Documents/someCo/applications/code/myApp/WEB-INF/}web-inf… [info] Resolving org.fusesource.jansi#jansi;1.4 … [info] Done updating. [info] Compiling 6 Scala sources and 4 Java sources to /home/me/Documents/someCo/applications/code/myApp/WEB-INF/target/scala-2.10/test-classes… [trace] Stack trace suppressed: run last test:compile for the full output. error java.io.IOException: Cannot run program “javac”: error=2, No such file or directory [error] Total time: 19 s, completed Nov 7, 2013 10:08:53 AM

I was able to get it to work again by modifying my path as follows:

me@myComputer:~/Documents/someCo/applications/code/myApp/WEB-INF$ echo $PATH /usr/lib/jvm/java-7-openjdk-amd64/bin:/home/me/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games me@myComputer:~/Documents/someCo/applications/code/myApp/WEB-INF$ PATH=/usr/lib/jvm/latest-oracle-jdk/bin:/home/me/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin me@myComputer:~/Documents/someCo/applications/code/myApp/WEB-INF$ $SBT_HOME/bin/sbt Loading /home/me/tools/sbt-0.13/bin/sbt-launch-lib.bash [info] Set current project to MyAwesomeAppTest (in build file:/home/me/Documents/someCo/applications/code/myApp/WEB-INF/) test [info] Compiling 6 Scala sources and 4 Java sources to /home/me/Documents/someCo/applications/code/myApp/WEB-INF/target/scala-2.10/test-classes…

Even More Desired Behavior Use -java-home if specified, else JDK_HOME if specified, else JAVA_HOME if specified, else try the PATH.

Actual Behavior JDK_HOME and JAVA_HOME are ignored. specifying -java-home works in some cases, but not in all.

System Details Ubuntu 12.04 64-bit java version “1.7.0_45” Java™ SE Runtime Environment (build 1.7.0_45-b18) Java HotSpot™ 64-Bit Server VM (build 24.45-b08, mixed mode)

Other java versions (before setting my path):

java -version java version “1.7.0_25” OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.12.04.2) OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

echo $JAVA_HOME /usr/lib/jvm/latest-oracle-jdk/jre

$JAVA_HOME/bin/java -version java version “1.7.0_45” Java™ SE Runtime Environment (build 1.7.0_45-b18) Java HotSpot™ 64-Bit Server VM (build 24.45-b08, mixed mode)

echo $JDK_HOME /usr/lib/jvm/latest-oracle-jdk

$JDK_HOME/bin/java -version java version “1.7.0_45” Java™ SE Runtime Environment (build 1.7.0_45-b18) Java HotSpot™ 64-Bit Server VM (build 24.45-b08, mixed mode)

Issue Analytics

  • State:open
  • Created 10 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
fommilcommented, Dec 7, 2015

I put a .sbtopts file in my base directory containing

-java-home
/path/to/jdk

must end with a newline.

1reaction
matanstercommented, Dec 7, 2015

Sorry to awaken this old thread but I am trying to build an sbt project with a JDK that is not my system-wide default one. (It is something I will also need to do as part of an automation script which builds projects with various JDK’s, so I cannot avoid needing this).

What may I expect not working with the javaHome := sys.env.get("JAVA_HOME") map file way? And just making sure, is https://github.com/paulp/sbt-extras paulp’s script, and does it take special fiddling to compile a project with a path to a given JDK?

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

JAVA_HOME set but not taking effect - Stack Overflow
I think in your path variable you have hardcoded the path to bin folder. it should always be %JAVA_HOME%/bin . So that it...
Read more >
Fix JAVA_HOME errors | Invalid directory | Not set or defined
The JAVA_HOME environment variable must point to the root of the installation folder of a JDK. It cannot point to a sub-directory of...
Read more >
How to set the JAVA_HOME environment variable?
To run JBoss product, I need to set the JAVA_HOME environment variable, ... The echo $JAVA_HOME command-line must return the complete path ...
Read more >
How to set JAVA_HOME on Windows 10? - Mkyong.com
In System variables, clicks New... button to add a new JAVA_HOME variable and point it to the JDK installed folder.
Read more >
JAVA_HOME vs. PATH Environment Variables - Tom Gregory
Some modern programs are intelligent enough to extract the JDK location from PATH if JAVA_HOME is not set. For example, with Gradle you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found