1

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

4
  • try this scala -cp "scalacheck_2.11-1.11.5.jar;." com.HelloWorld Commented Sep 6, 2014 at 18:21
  • I stiil get the error "No such file or class on classpath: com.HelloWorld" Commented Sep 6, 2014 at 18:22
  • 2
    You'll be much, much happier if you start using a build system as soon as you can. This would require two lines of configuration and SBT and then you never have to worry about your classpath again (not really, but closer). Commented Sep 6, 2014 at 18:46
  • I was trying to get this working using first principals (from the cmd line using scalac and scala). With SBT ScalaCheck is working. Commented Sep 6, 2014 at 18:50

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

Yes works with : (colon) as seperator. Thank you Loki.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.