main

A Kotlin Adler-32 checksum algorithm

As a short post today, here’s an example of a Kotlin implementation of the Adler-32 checksum algorithm:

Scala/SBT: How to specify a main method/class to run

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 18.9, “Specifying a Main Class to Run with SBT.”

Problem

In a Scala SBT project, you have multiple main methods in objects in your project, and you want to specify which main method should be run when you type sbt run, or specify the main method that should be invoked when your project is packaged as a JAR file.

How to run a Scala SBT-packaged jar file with Java (the `java` command)

If you want to run/execute a main method from a jar file you created with Scala and the sbt package command, this little tutorial shows how to do it. To make things a little more complicated, my Scala project depends on three external jar files, and the main method requires a command-line argument.

As noted in the Summary, you’ll probably want to use a tool like SBT-Assembly for larger projects.

How to launch a Scala application with an object (main, app)

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 6.4, “How to launch a Scala application with an object.”

Problem

You want to start an application with a main method, or provide the entry point for a script.

Solution

There are two ways to create a launching point for your application: define an object that extends the App trait, or define an object with a properly defined main method.

How to run a Scala application in a jar file while setting the classpath

I don’t know why, but without digging into it more, all I can say right now is that I can’t use the Java Sound API from within SBT. Whenever I try running sbt run, I keep getting the following error message, even though I know that my app and sound file work fine when I package my Java application normally:

javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file

As part of the debugging process I created a little shell script named run.sh that contained these two lines: