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

  • YOU + CONTROL
  • Focus
  • Autonomy
  • Proficiency
  • Purpose
  • Covid-19!!!
  • Deep Hidden Meaning
  • FREE updates
EARLY ACCESS (VIP)
Exclusively on
VIMEO ON-DEMAND

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

26 July 2012 Comments off

6 minutes

1235

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 =>
  Seq(
    base / "src",
    base / "demo"
  )
}

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

// testListeners <<= target.map(t => 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 += "com.oracle" % "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("user.name") + " (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" ,
  "-Djavafx.verbose"
)

// 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
host=nexus.scala-tools.org
user=admin
password=admin123
*/
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")

// Directly specify credentials for publishing.
credentials += Credentials("Sonatype Nexus Repository Manager", "nexus.scala-tools.org", "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.app/Contents/MacOS/Java\ Preferences 
-rwxr-xr-x  1 root  wheel  39072 18 Jul 02:55 /Applications/Utilities/Java Preferences.app/Contents/MacOS/Java Preferences*
> /Applications/Utilities/Java\ Preferences.app/Contents/MacOS/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
/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/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

/Library/Java/JavaVirtualMachines/1.7.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" "https://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
	<dict>
		<key>JVMArch</key>
		<string>x86_64</string>
		<key>JVMBlacklisted</key>
		<false/>
		<key>JVMBundleID</key>
		<string>com.oracle.java.7u05.jdk</string>
		<key>JVMEnabled</key>
		<true/>
		<key>JVMHomePath</key>
		<string>/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home</string>
		<key>JVMIsBuiltIn</key>
		<false/>
		<key>JVMName</key>
		<string>Java SE 7</string>
		<key>JVMPlatformVersion</key>
		<string>1.7</string>
		<key>JVMVendor</key>
		<string>Oracle Corporation</string>
		<key>JVMVersion</key>
		<string>1.7.0_05</string>
	</dict>
	<dict>
		<key>JVMArch</key>
		<string>x86_64</string>
		<key>JVMBlacklist
        ...
</plist> 

+PP+

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.