Skip to content
Snippets Groups Projects
Commit 3bb2933c authored by Jari-Matti Mäkelä's avatar Jari-Matti Mäkelä
Browse files

SBT version

parent 6a52138b
Branches
No related tags found
No related merge requests found
*.class
*.log
*.iml
*.ipr
*.iws
.idea
out
.cache/
.history/
.lib/
dist/*
target/
bin/
libexec/
lib_managed/
src_managed/
project/boot/
project/plugins/project/
logs/
project/*-shim.sbt
project/project/
project/target/
target/
.scala_dependencies
.worksheet
## JavaFX Hello world
# templates-jqwik-test
### Eclipsellä
Simple test template for Java 11 / JQwik / JUnit / Cofoja / JavaFX projects.
* Asenna Java (mielellään versio 11, mutta versiot 10 tai 8 voivat myös toimia)
* Versio 8 on vielä tuettu
* Versioden 1-7 ja 9-10 tuki on virallisesti loppunut
## Requirements
* Asenna Eclipse
* versio: Eclipse IDE for Java Developers
* testattu versiolla 4.10 / 2018-12
- OpenJDK / Oracle Java (tested with OpenJDK 11)
- SBT (tested with SBT 1.2.8, see https://www.scala-sbt.org/)
- Git (see https://git-scm.com/downloads/)
- JavaFX platform files (see https://gluonhq.com/products/javafx/)
* Varmista että Eclipseen on asennettu Eclipse Egit (git-tuki) ja Eclipse m2e (Maven-tuki).
* Jos jompi kumpi puuttuu, etsi netistä ohjeet näiden asentamiseksi
* pluginien pitäisi olla 2018-12 Java-versiossa
The SBT project build file downloads all further requirements:
- JUnit 5
- JQwik
- OpenJFX (JavaFX)
- other plugins
* Käynnistä Eclipse
* Valitse ylävalikosta File
* -> Import
* -> Git -> Projects from Git -> Next -> Clone URI -> Next
* kohtaan URI syötä: https://gitlab.utu.fi/jmjmak/fxhello
* voit tallentaa utu-tunnukset user/password -kohtiin alle, jos haluat myöhemmin säästää kirjoitusvaivaa, mutta jos epäilet Eclipsen/koneen tietoturvaa, jätä tallentamatta
* valitse Next -> Next -> Next (tämä kolmas Next ei toimi, jos olet jo hakenut projektin - poista ensin vanha, vinkki: hakemisto lukee Directory-kohdassa)
* valitse Next -> Finnish
## Preparation
* Projektin nimi on nyt 'hellofx'.
- Install Java JDK, not just the JRE.
- Install SBT and Git.
- Install IntelliJ IDEA for IDE support
- Install IntelliJ IDEA plugins "Git", "Gitlab projects", and "Scala".
- Download JavaFX platform files. (unless the JDK already includes them)
- Set the environment variables PATH and JAVAFX_HOME.
- The environment variables might become effective only after logout/login.
- 'git clone' this project (or download the zip from the cloud icon above)
- Import the project from the project directory in the IDE.
* Valitse ylävalikosta Run -> Run -> Maven build -> OK
## Usage
* Myöhemmillä käyttökerroilla riittää valita vain Run -> Run -> ...
Use 'sbt run' or 'sbt test' to run the main class / tests.
Use 'sbt assembly' to build a 'fat jar' that can be started
without any dependencies.
### Komentoriviltä
If you want to use Eclipse/Netbeans, the project file can be exported
with command 'sbt eclipse' and 'sbt netbeans'.
* Asenna Java (mielellään versio 11, mutta versiot 10 tai 8 voivat myös toimia)
* Versio 8 on vielä tuettu
* Versioden 1-7 ja 9-10 tuki on virallisesti loppunut
* Tarkasta että käskyt java ja javac toimivat (PATH-ympäristömuuttuja)
## JavaFX
* Asenna Maven. Tarkasta että käsky mvn toimii (PATH-ympäristömuuttuja)
The build configuration also supports JavaFX.
* Asenna Git. Tarkasta että käsky git toimii (PATH-ympäristömuuttuja
If you use Oracle JDK 8/10, it should just work.
* git clone https://gitlab.utu.fi/jmjmak/fxhello
* mvn exec:java
If you use OpenJDK 8/10/11 or Oracle JDK 11+, remember to install
OpenJFX separately.
### Problems
Tested with OpenJDK 11.
Jos ohje ei toimi, yritä seuraavia
* https://github.com/openjfx/samples
## Environment variables
### JAVAFX_HOME (optional)
JAVAFX_HOME should point to a directory where one has unzipped
the platform SDK. See https://gitlab.utu.fi/jmjmak/openjfx for
further instructions.
Note: JAVAFX_HOME is not necessarily needed anymore. If you
forget to set it, the build.sbt script fetches OpenJFX for each
project separately, which can take a while.
### PATH
PATH should include both Java binaries and the SBT launcher binary
'sbt'. This is important! At least on Windows the PATH is not set
up properly by default.
build.sbt 0 → 100644
// Project template
//
// This version should now automatically detect and fetch things.
// Supported OS/JDK combos:
// - Windows: Oracle JDK 8, 10, 11
// - Mac: OpenJDK 8, 10, 11 (not tested on Mac)
// - Linux: OpenJDK 8, 10, 11
// However, you can configure stuff with environment variables:
// JAVA_HOME -- where to look for the java runtime
// JAVAFX_HOME -- where to look for JavaFX (10/11)
// Project name
name := "fxhello"
// organization name
organization := "fi.utu"
version := "1.0"
// project description
description := "Simple test template for java / javafx projects"
// force the java version by typing it here (remove the comment)
val force_javaVersion = None // Some(11)
// force the javafx version by typing it here (remove the comment)
val force_javaFxVersion = None // Some(11)
// END_OF_SIMPLE_CONFIGURATION
// you can copy the rest for each new project
// --- --- ---
// the script will automatically pick the best libraries for you
val javaVersionNum = force_javaVersion getOrElse {
var sysVersion = System.getProperty("java.version")
if (sysVersion.startsWith("1."))
sysVersion = sysVersion.drop(2)
sysVersion.split('.').head.toInt
}
val javaVersionString = javaVersionNum match {
case 7 => "1.7"
case 8 => "1.8"
case 10 => "10"
case 11 => "11"
case _ => throw new Exception("Unsupported Java version. Use 7/8/10/11")
}
javacOptions ++= Seq("-source", javaVersionString, "-target", javaVersionString, "-encoding", "utf8")
compileOrder := CompileOrder.JavaThenScala
// Enables publishing to maven repo
publishMavenStyle := true
// Do not append Scala versions to the generated artifacts
crossPaths := false
// This forbids including Scala related libraries into the dependency
autoScalaLibrary := false
assemblyMergeStrategy in assembly := {
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
case _ => MergeStrategy.first
}
// we'll get rid of this once 1.3.2 has been released
resolvers += "utujemma" at "http://users.utu.fi/jmjmak/repository/"
//// JQWIK / JUNIT configuration
// library dependencies. (orginization name) % (project name) % (version)
// jqwik 0.8.15 still depends on old junit
libraryDependencies ++= Seq(
"org.junit.platform" % "junit-platform-commons" % "1.2.0",
"org.junit.platform" % "junit-platform-runner" % "1.2.0",
"org.junit.jupiter" % "junit-jupiter-engine" % "5.2.0",
"org.junit.jupiter" % "junit-jupiter-api" % "5.2.0",
"org.junit.jupiter" % "junit-jupiter-migrationsupport" % "5.2.0",
"org.junit.jupiter" % "junit-jupiter-params" % "5.2.0",
"net.jqwik" % "jqwik" % "0.8.15"
)
testOptions += Tests.Argument(TestFrameworks.JUnit, "-q", "-c")
fork in Global := true
//// JAVAFX configuration
val javafx_version = force_javaFxVersion getOrElse (javaVersionNum match {
case 7 => 7
case 8 => 8
case 10 | 11 => 11
case _ => throw new Exception("Unsupported JavaFX version. Use 7/8/10/11.")
})
// JAVA_HOME location
val javaHomeDir = {
val path = try {
scala.sys.env("JAVA_HOME")
} catch {
case _: Throwable => System.getProperty("java.home") // not set -> ask from current JVM
}
val f = file(path)
if (!f.exists()) throw new Exception("JAVA_HOME points to a non-existent directory! Read the course instructions once more!")
f
}
val osName: SettingKey[String] = SettingKey[String]("osName")
osName := (System.getProperty("os.name") match {
case n if n.startsWith("Linux") => "linux"
case n if n.startsWith("Mac") => "mac"
case n if n.startsWith("Windows") => "win"
case _ => throw new Exception("Unknown platform!")
})
def legacyJavaFX(jfxVersion: Int, badVersions: Seq[Int]) = {
val searchDirs = Seq(
"/jre/lib/jfxrt.jar", // OpenJDK 7
"/jre/lib/ext/jfxrt.jar", // OpenJDK 8
"/lib/ext/jfxrt.jar" // Windows & Oracle Java 8
)
val javaFxJAR = searchDirs.map{ searchDir => file(javaHomeDir + searchDir) }.find{ _.exists() }
javaFxJAR.getOrElse {
val p = javaHomeDir.toString
throw new Exception("Java FX runtime not installed in [" + p + "]!" +
(if (badVersions.exists { v => p.contains("jdk-" + v) }) " Did you try to run JavaFX " + jfxVersion + " with JDK " + badVersions.sorted.mkString("/") + "?" else "") +
" Read the course instructions once more!"
)
}
}
val javaFxPath = Def.taskKey[File]("OpenJFX fetcher")
javaFxPath := {
try {
val javaFxHome = file(scala.sys.env("JAVAFX_HOME"))
if (!javaFxHome.exists()) throw new Exception("JAVAFX_HOME points to a non-existent directory! Read the course instructions once more!")
println("Using OpenJFX from " + javaFxHome)
javaFxHome
}
catch {
case _: Throwable =>
println("Using local OpenJFX")
val dir = baseDirectory.value / "openjfx"
if (!dir.exists()) java.nio.file.Files.createDirectory(dir.toPath)
val sdkURL = "http://download2.gluonhq.com/openjfx/11/openjfx-11_" + (osName.value match {
case "linux" => "linux"
case "mac" => "osx"
case "win" => "windows"
}) + "-x64_bin-sdk.zip"
try {
val testDir = dir / "all.ok"
if (!testDir.exists()) {
println("Fetching OpenJFX from "+sdkURL+"..")
IO.unzipURL(new URL(sdkURL), dir)
java.nio.file.Files.createDirectory(testDir.toPath)
println("Fetching OpenJFX done.")
} else {
println("Local OpenJFX found from "+dir)
}
dir
}
catch {
case t: Throwable => throw new Exception("Could not load OpenJFX! Reason:" + t.getMessage)
}
}
}
javafx_version match {
case 7 =>
// TODO libraryDependencies
Seq(unmanagedJars in Compile += Attributed.blank(legacyJavaFX(8, Seq(10, 11, 8))))
case 8 =>
Seq(
libraryDependencies += "org.scalafx" %% "scalafx" % "8.0.144-R12",
unmanagedJars in Compile += Attributed.blank(legacyJavaFX(8, Seq(10, 11, 7))),
)
case 11 =>
Seq(
javaOptions ++= Seq(
"--module-path", (javaFxPath.value / "javafx-sdk-11" / "lib").toString,
"--add-modules=javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web"),
libraryDependencies ++= Seq(
"org.scalafx" % "scalafx_2.12" % "11-R16",
"org.openjfx" % "javafx-base" % "11.0.2" classifier osName.value,
"org.openjfx" % "javafx-controls" % "11.0.2" classifier osName.value,
"org.openjfx" % "javafx-fxml" % "11.0.2" classifier osName.value,
"org.openjfx" % "javafx-graphics" % "11.0.2" classifier osName.value,
"org.openjfx" % "javafx-media" % "11.0.2" classifier osName.value,
"org.openjfx" % "javafx-swing" % "11.0.2" classifier osName.value,
"org.openjfx" % "javafx-web" % "11.0.2" classifier osName.value
)
)
}
import xml.transform.{RewriteRule, RuleTransformer}
import xml.{Node,NodeSeq,Elem}
pomPostProcess := {
def rule(f: PartialFunction[Node, NodeSeq]): RewriteRule = new RewriteRule {
override def transform(n: Node) = if (f.isDefinedAt(n)) f(n) else n
}
def depName(e: Elem) =
Seq(e).filter(_.label == "dependency").flatMap(_.child).filter{_.label == "artifactId" }.flatMap(_.child).mkString
def toolVersions =
<properties>
<maven.compiler.source>{javaVersionString}</maven.compiler.source>
<maven.compiler.target>{javaVersionString}</maven.compiler.target>
</properties>
new RuleTransformer(rule {
case e: Elem if depName(e) == "jupiter-interface" => println("Skipped "+depName(e)); NodeSeq.Empty
case e: Elem if e.label == "organization" => NodeSeq.seqToNodeSeq(Seq(e, toolVersions))
})
}
val javaVersion = taskKey[Unit]("Prints the Java version.")
javaVersion := { println("SBT uses Java SDK located at "+System.getProperty("java.home")) }
val netbeans = taskKey[Unit]("Makes a Netbeans compatible pom.xml.")
val eclipse = taskKey[Unit]("Makes a Eclipse compatible pom.xml.")
netbeans := {
println("Tehdään Netbeans-yhteensopiva pom.xml!")
IO.copyFile(makePom.value, file("pom.xml"))
}
eclipse := {
println("Tehdään Eclipse-yhteensopiva pom.xml!")
IO.copyFile(makePom.value, file("pom.xml"))
}
publishTo := Some(Resolver.file("file", new File("/tmp/repository")))
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.openjfx</groupId>
<artifactId>hellofx</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>hellofx</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.openjfx.MainApp</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
sbt.version=1.2.8
resolvers += Resolver.jcenterRepo
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.9")
module hellofx {
requires javafx.controls;
requires javafx.fxml;
requires transitive javafx.graphics;
opens org.openjfx to javafx.fxml;
exports org.openjfx;
}
\ No newline at end of file
......@@ -17,7 +17,7 @@ public class MainApp extends Application {
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("styles.css").toExternalForm());
stage.setTitle("JavaFX and Maven");
stage.setTitle("JavaFX and SBT");
stage.setScene(scene);
stage.show();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment