Await Scala Futures

Here’s Scala example code that creates 100 Futures and waits for all of them to complete. This is using the global ExecutionContext.

import scala.concurrent.{Future, Await, future}
import scala.concurrent.duration.Duration
import scala.concurrent.ExecutionContext.Implicits.global

object WaitForAllFutures extends App {

    val futures = (1 to 100).map { i =>
      future {
        Thread.sleep(5000)
        println(s"Future $i done.")
      }
    }

    Await.result(Future.sequence(futures), Duration.Inf)
}

XSD to JAR using JAXB Binding Compiler

Here are the contents of our batch file that converts a .xsd file into a .jar file. It uses xjc, so you can use JAXB to convert objects to XML and vice versa.

@echo off

set INPUT_XSD=..\sample.xsd
set OUTPUT_JAR=sample.jar

mkdir ~dir
cd ~dir

xjc.exe %INPUT_XSD%

dir /s /B *.java > ~list
javac @~list
del ~list

jar cf ../%OUTPUT_JAR% *

cd ..

rmdir ~dir /s /q

Maven Generated Eclipse Project with WTP

To create an Eclipse project with Web Tools Platform (WTP) support, run the following command.

mvn eclipse:eclipse -Dwtpversion=2.0