How do you create Scala SWT project in SBT?
I know that you can use GIT repositories:
RootProject(uri("http://git.eclipse.org/gitroot/platform/eclipse.platform.swt.binaries.git"))
But I don't know how and if it is possible with SWT.
Thanks in advance, Etam.
EDIT:
I had to download it manually. It compiles but while running I get Invalid thread access error:
***WARNING: Display must be created on main thread due to Cocoa restrictions.
[error] (run-main) org.eclipse.swt.SWTException: Invalid thread access
Even if I use:
javaOptions := Seq("-XstartOnFirstThread", "-d64")
This is the main class:
import org.eclipse.swt._
import org.eclipse.swt.layout._
import org.eclipse.swt.widgets._
object Main extends App {
    val display = new Display
    val shell = new Shell(display)
    shell.setLayout(new GridLayout())
    shell.pack
    shell.open
    while (!shell.isDisposed) {
        if (!display.readAndDispatch)
            display.sleep
    }
    display.dispose
}
Thanks again, Etam.
Add this to your build.sbt:
resolvers += "swt-repo" at "http://maven-eclipse.github.io/maven"
libraryDependencies += {
  val os = (sys.props("os.name"), sys.props("os.arch")) match {
    case ("Linux", _) => "gtk.linux.x86"
    case ("Mac OS X", "amd64" | "x86_64") => "cocoa.macosx.x86_64"
    case ("Mac OS X", _) => "cocoa.macosx.x86"
    case (os, "amd64") if os.startsWith("Windows") => "win32.win32.x86_64"
    case (os, _) if os.startsWith("Windows") => "win32.win32.x86"
    case (os, arch) => sys.error("Cannot obtain lib for OS '" + os + "' and architecture '" + arch + "'")
  }
  val artifact = "org.eclipse.swt." + os
  "org.eclipse.swt" % artifact % "4.6.1"
}
It will first add a resolver for the SWT artifact repository. It will then detect your OS version and download an appropriate JAR for it.
As for the thread access problem, I solved this on Mac OS X by using JDK 1.6 with it - when I specify -XstartOnFirstThread there, it works fine. I've found no solution for JDK 1.7.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With