Member-only story
A tiny guide to quickly test driving a library in Scala
Feb 25, 2020
Java has about a googol available libraries for your software enjoyment. Most of them deployed to Maven repositories. If want a fast way to try them out, you can quickly load them from a remote repository and take them for a test drive using Ammonite. So go install Ammonite and fire it up.
Simple Example:
// Import a library from a Maven repository
import $ivy.`org.apache.commons:commons-text:1.2`
import org.apache.commons.text.RandomStringGenerator// Use classes from the library
val generator = new RandomStringGenerator.Builder()
.withinRange('a', 'z')
.build()
println(generator.generate(20))
Advance Example:
Here we add a custom repository:
// Add a repository
interp.repositories() ++= Seq(
coursierapi
.MavenRepository
.of("https://dl.bintray.com/org-mbari/maven"))// This ampersand denotes a separate compilation block.
@import $ivy.`org.mbari:mbarix4j:2.0.5.jre11`
import mbarix4j.math.MatlibMatlib.diff(Array(2, 4, 6))