PEAT Online Course -
How To Improve Your Personal Performance in Java work Technology

  • Focus
  • Autonomy
  • Proficiency
  • Purpose
  • Covid-19!!!
  • Deep Hidden Meaning
  • FREE updates
Your Promo code: TECHLAYOFF
Exclusively on

ScalaFX – Working Configuration for MacOS X Lion, Java 7 Update 5

26 July 2012 Comments off

6 minutes


Here is a complete verbatim build.sbt for ScalaFX that works on MacOS X Lion and Java SE 7 Update 5:

// Important - Set the JAVAFX_HOME environment variable to the root of your JavaFX installation for this script to work

// You can also set your scala or java home if necessary like this:
// javaHome := Some(file("/Library/Java/JavaVirtualMachines/1.6.0_24-b07-330.jdk/Contents/Home"))
// scalaHome := Some(file("/Users/Sven/scala-2.9.1/"))
// javaHome := Some(file("/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home"))

javaHome := Some(file(System.getenv("JAVA_HOME")))

name := "ScalaFX"

version := "1.0-SNAPSHOT"

organization := "org.scalafx"

scalaVersion := "2.9.2"

resolvers += "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository"

unmanagedSourceDirectories in Compile <++= baseDirectory { base =>
    base / "src",
    base / "demo"

// set the Scala test source directory to be <base>/test
scalaSource in Test <<= baseDirectory(_ / "test")

// testListeners <<= => Seq(new eu.henkelmann.sbt.JUnitXmlTestsListener(t.getAbsolutePath)))

// append several options to the list of options passed to the Java compiler
javacOptions ++= Seq("-source", "1.5", "-target", "1.5")

// append -deprecation to the options passed to the Scala compiler
scalacOptions += "-deprecation"

// define the statements initially evaluated when entering 'console', 'console-quick', or 'console-project'
initialCommands := """
  import System.{currentTimeMillis => now}
  def time[T](f: => T): T = {
    val start = now
    try { f } finally { println("Elapsed: " + (now - start)/1000.0 + " s") }

// libraryDependencies += "" % "javafx-runtime" % "2.1"

// set the main class for the main 'run' task
// change Compile to Test to set it for 'test:run'
mainClass in (Compile, run) := Some("scalafx.ColorfulCircles")

// add <base>/input to the files that '~' triggers on
watchSources <+= baseDirectory map { _ / "input" }

// disable updating dynamic revisions (including -SNAPSHOT versions)
offline := true

// set the prompt (for this build) to include the project id.
shellPrompt in ThisBuild := { state => Project.extract(state).currentRef.project + "> " }

// set the prompt (for the current project) to include the username
shellPrompt := { state => System.getProperty("") + " (SBT) > " }

// disable printing timing information, but still print [success]
showTiming := false

// disable printing a message indicating the success or failure of running a task
showSuccess := false

// change the format used for printing task completion time
timingFormat := {
    import java.text.DateFormat
    DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)

// disable using the Scala version in output paths and artifacts
crossPaths := false

// fork a new JVM for 'run' and 'test:run'
fork := true

// fork a new JVM for 'test:run', but not 'run'
fork in Test := true

// add a JVM option to use when forking a JVM for 'run'
javaOptions ++= Seq (
  "-Xmx512M" ,

// only use a single thread for building
parallelExecution := false

// Execute tests in the current project serially
//   Tests from other projects may still run concurrently.
parallelExecution in Test := false

// add JavaFX 2.0 to the unmanaged classpath
unmanagedJars in Compile += Attributed.blank(file(System.getenv("JAVA_HOME") + "/jre/lib/jfxrt.jar"))

// publish test jar, sources, and docs
publishArtifact in Test := false

// disable publishing of main docs
publishArtifact in (Compile, packageDoc) := false

// change the classifier for the docs artifact
artifactClassifier in packageDoc := Some("doc")

// Copy all managed dependencies to <build-root>/lib_managed/
//   This is essentially a project-local cache and is different
//   from the lib_managed/ in sbt 0.7.x.  There is only one
//   lib_managed/ in the build root (not per-project).
retrieveManaged := true

/* Specify a file containing credentials for publishing. The format is:
realm=Sonatype Nexus Repository Manager
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")

// Directly specify credentials for publishing.
credentials += Credentials("Sonatype Nexus Repository Manager", "", "admin", "admin123")

publishMavenStyle := true

publishTo := Some(Resolver.file( "file",  new File( Path.userHome + "/.m2/repository" )) )
# End

Java 7 up to Update 5 already includes JavaFX 2.1. Therefore there is no need to explicitly install in the jfxrt.jar inside a Maven directory. However, I am unsure how to link ScalaFX with JavaFX 2.2 beta and 3.0 code from the OpenJfx repositories; and how the platform toolkit with those codebases for Mac OS X explicitly loads native libraries at initialisation.

On a new Mac OS machine, especially Lion, you will definitely want to re-enable Java to run inside web browsers. You might also want to prefer to use as a default the Java SE 7 from Oracle instead of the Apple JDK 6 release. Fire up the Java Preferences App. Open a terminal and execute the following command at the Bash shell prompt.

> ls -lF /Applications/Utilities/Java\\ Preferences 
-rwxr-xr-x  1 root  wheel  39072 18 Jul 02:55 /Applications/Utilities/Java Preferences*
> /Applications/Utilities/Java\\ Preferences  

Re-enable JRE to run inside all of your installed web browsers: Firefox, Chrome and Safari. Select Java 7 Runtime Environment with the mouse, drag it to the top of the list. Check that Java 7 is now the default.

> /usr/libexec/java_home

You can add this call to your ~/.bash_profile script, so your Java environment is automated every time you fire up a terminal command.

export JAVA_HOME=`/usr/libexec/java_home`

export PATH=${JAVA_HOME}/bin:${JAVA_HOME}/jre/bin:[whatever your path was before>]

Finally, the java_home program can dump a list of your installed JREs.

macosx [248] > /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
    1.7.0_05, x86_64:	"Java SE 7"	/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home
    1.6.0_33-b03-424, x86_64:	"Java SE 6"	/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_33-b03-424, i386:	"Java SE 6"	/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

macosx [249] > /usr/libexec/java_home -X
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
		<string>Java SE 7</string>
		<string>Oracle Corporation</string>


Hey all! Thanks for visiting. I provide fringe benefits to interested readers: checkout consultancy, training or mentorship Please make enquiries by email or
call +44 (0)7397 067 658.

Due to the Off-Payroll Working plan for the UK government, I am enforcing stricter measures on contracts. All potential public sector GOV.UK contracts engagements must be approved by QDOS and/or SJD Accounting. Please enquire for further information.