Working with Vaadin, Jetty, Scala and Eclipse, I’ve seen intermittent deployment failures in which the web application would fail with a 500 error and
Problem accessing /HomepageDashboard/. Reason:
scala/ScalaObject
Caused by:
java.lang.NoClassDefFoundError: scala/ScalaObject
The problem is that the scala library files are not being copied correctly into the WEB-INFO/lib directory. This omission can be verified by [...]
In the previous post, I showed how to call multivariate linear regression functions in the Apache Commons Math Statistics library. You might want to compare your results to Excel, perhaps to check your implementation or because you manually develop your analytic process before automating it in code. Here are some tips for comparing Excel results [...]
Linear Regression in Scala is as easy as calling the routines in the Apache Commons Math jar. We just need to add the calculation of the correlation coefficient, aka r^2, to see how well we fit. Here’s how:
Download the library from here and put the commons-math-2.1.jar file on your classpath. Here’s the example in the [...]
Continue reading about Easy Multivariate Linear Regression in Scala
Here’s a way to ensure that only one instance of your application runs at a time. Perhaps it updates a resource and you need to prevent duplicate updates. Or, in another use, I recently wanted to make sure an application was always running. So I wrote a cron job to periodically start the program; if [...]
Continue reading about SingletonApp: How to run only one application instance at a time in Scala
Sometimes you need the top k items in a list. A naive way to do it is to sort the list, then take the first k items. The problem with that approach is that you don’t need to sort the whole list, so it’s inefficient and becomes more so as the list length, n, increases [...]
If you’ve played around with the Option class, you know that it allows you to note that no value is available and do so without nulls. For example, using getOrElse() you can access a value or a default when no value is present:
scala> val a:Option[Int] = Some(5)a: Option[Int] = Some(5)scala> val b:Option[Int] = None b: [...]
// Sum the values in a list
val sum = (0.0 /: list){ _ + _ }
// What it says: it’s an abbreviated form of
// list.leftFold(0.0) { (s,i) => s + i }
// Find the minimum value in a list
val minValue = list.reduceLeft( _ min _ )
// What it says: Note that it’s reduce, not fold. [...]
Trying to start a program created with the eclipse Scala plugin, I saw an error that the main class couldn’t be found. That was cryptic, as there was a main. Stranger still, this is a program I had run successfully before.
The first part of solving the problem was to look for clues in the [...]
Continue reading about Scala Eclipse Plugin Error: Scala Signature
In NetBeans, creating a runnable jar for your Scala program is even easier. It’s done automatically when you build your project. The compile output even reminds you how to run the jar file.
The first time I did it, I saw an error about finding a Scala object. Solve that by adding the scala-library.jar to your [...]
Continue reading about Creating Single-file Runnable Jars in Scala with NetBeans
How do you create a single runnable jar that contains all the files it needs to run? This is one of those questions that should be easier to answer. Here’s how to do it in eclipse and NetBeans.
First, eclipse, following the post here:1. Create a Java class to run your Scala main:
package scala.loader;
import java.util.*;
public class [...]
Continue reading about Creating Single-file Runnable Jars in Scala with eclipse