Search code examples
scalascalacheck

Scala class not found on classpath when specifying jar in classpath


I am attempting to use ScalaCheck. Below is my HelloWorld.scala Scala code which imports from ScalaCheck and uses the Gen.const method.

package com

import org.scalacheck._
import org.scalacheck.Gen._
import org.scalacheck.Arbitrary.arbitrary

sealed abstract class Tree
case class Node(left: Tree, right: Tree, v: Int) extends Tree
case object Leaf extends Tree

object HelloWorld {
 val genLeaf = Gen.const(Leaf)

 def main(args: Array[String]) {
    println("Hello, world!")
 }
}

Compile by typing (this works)

scalac -cp scalacheck_2.11-1.11.5.jar com/HelloWorld.scala 

Execute by typing (2 alternatives)

scala -cp scalacheck_2.11-1.11.5.jar com.HelloWorld
scala -cp "scalacheck_2.11-1.11.5.jar;./com" com.HelloWorld

Output of scala

No such file or class on classpath: com.HelloWorld

When I remove all ScalaCheck code in HelloWorld.scala and compile without using the -cp flag everything works. When adding the ScalaCheck code and the jar to the -cp flag, I get the above error.

How do I correctly setup the classpath?

(Versions:

scalac -version

Scala compiler version 2.11.2 -- Copyright 2002-2013, LAMP/EPFL

scala -version

Scala code runner version 2.11.2 -- Copyright 2002-2013, LAMP/EPFL

)

OS: Linux


Solution

  • Which OS are you using? If not Windows, the path separator should be :, try this

    scala -cp "scalacheck_2.11-1.11.5.jar:." com.HelloWorld