Excluding Folders in Play Framework 2.2 dist

We have a Play Framework 2.2 application that uses Gulp to optimize the public files. Gulp uses Node.js and it creates a public\node_modules directory. We don’t need the node_modules directory at runtime so we want to remove it when running the Play “dist” command.

1. In build.sbt, add the following lines.

mappings in (Compile, packageBin) ~= { _.filterNot { case (_, name) =>
	  name.startsWith("public\\node_modules")
}}

packageBin is the task that creates the project JAR under Compile scope. mappings are the files used during compilation and packaging. We filter out all the files that are under “public\node_modules”.

2. We also want to to remove the share folder. So we added the following lines in build.sbt as well.

doc in Compile <<= target.map(_ / "none")

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