Archive

Archive for the ‘Framework’ Category

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

July 26th, 2012 Comments off

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" "http://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+

ScalaFX – Some Workarounds for SBT Issues

July 24th, 2012 Comments off

ScalaFX build does not work out of the box with SBT. Here is a little bit of extra help if you are new to ScalaFX, Scala and SBT; and are attempting to build the project yourself.

The Plugin configuration has the wrong URL, if your set up does not allow GIT as HTTP protocol. Fortunately, one can easily fix this by changing it to HTTPS.

Edit projects/plugins/project/PluginBuild.scala file

import sbt._

object MyPlugins extends Build {
  lazy val root = Project("root", file(".")) dependsOn (junitXmlListener)
  lazy val junitXmlListener = uri("git://github.com/ijuma/junit_xml_listener.git#fe434773255b451a38e8d889536ebc260f4225ce")
}

Change the Protocol from "git://..." to "https://github.com"

Next, edit the build.sbt in the root folder of the project. Uncomment or remove the line:-

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

I am unsure why the Xml test listener was needed in the first place. However, we do not need it out of the box to compile and build the project.

Finally, upgrade the Scala version of the project to a 2.9.2 if you want

scalaVersion := "2.9.2"

In the ScalaFX, there are two source code roots.

unmanagedSourceDirectories in Compile <++= baseDirectory { base =>
  Seq(
    base / "src",
    base / "demo"
  )
}

No changes are required here. It is decidedly a un-Maven like structure for a project.

I believe, actually, we should split up the ScalaFX project into multiple modules. One module for the core and the other for the demonstrations. Lots of engineers are familiar with this type project organisation coming from Maven style world. The project committers, however, need to agree to this manoeuvre.

In the recent JavaPosse Episode 390, Dick Wall had some comments to say about the SBT. I agree with many of his comments that SBT is no longer a simple build tool. It is anything but. It is quite hard to get your head around this domain specific language and it is an illustration when such a DSL becomes a burden on the developer, its user base. Were it not for the fact that very fast build times are achievable, because of its incremental compilation features, I believe many users would leave SBT behind.

+PP+

Categories: Framework, JavaFX, Rich User Interface, Scala Tags:

ScalaFX A Walk Through

November 5th, 2011 Comments off

In this video cast, I walk you through downloading ScalaFX and setting up the environment for IntelliJ IDEA 10.5 with Scala Build Tool (SBT) in real-time.

 

 

ScalaFX is a domain specific language and binding framework written in Scala that wraps the JavaFX 2.0 application programming interface.

Information of Scala Build Tool can be found here.

I also just discovered the command input line failure with SBT for IntelliJ Plug-in can be fixed, by updating the plug-in. Just go to the update site.

Give us a bell please, if you have any questions. Thank you.

-PP-

Categories: Design, DSL, Framework, JavaFX, Scala, technical, UI Tags: