Scala classpath not finding default package class in local directory

425 views Asked by At

Consider a v simple scala object with the following first two lines (default/no package) and a main():

object CpuTest {
 def main(args: Array[String]) = {
      ..

Compiling works fine

stephen@i386:/shared/OpenChai/dstat$ scalac CpuTest.scala

Here are the classes:

stephen@i386:/shared/OpenChai/dstat$ ls -l *.class
-rw-rw-r-- 1 stephen stephen 1150 Jun 10 20:06 CpuTest$$anonfun$1.class
-rw-rw-r-- 1 stephen stephen  667 Jun 10 20:06 CpuTest.class
-rw-rw-r-- 1 stephen stephen 1748 Jun 10 20:06 CpuTest$.class
-rw-rw-r-- 1 stephen stephen 2175 Jun 10 20:06 CpuTest$MyThread$1$$anonfun$run$1.class
-rw-rw-r-- 1 stephen stephen 1444 Jun 10 20:06 CpuTest$MyThread$1.class

And javap is happy with it:

stephen@i386:/shared/OpenChai/dstat$ javap CpuTest.class
Compiled from "CpuTest.scala"
public final class CpuTest {
  public static void main(java.lang.String[]);
}

But I can not get the classpath to work to run this class:

export CLASSPATH="$(pwd)/*"

echo "$CLASSPATH"
/shared/OpenChai/dstat/*

stephen@i386:/shared/OpenChai/dstat$ scala CpuTest
No such file or class on classpath: CpuTest
stephen@i386:/shared/OpenChai/dstat$ scala -classpath "$CLASSPATH" CpuTest
No such file or class on classpath: CpuTest

This should be dead simple. What am I missing?

Update I found a workaround: need to add "." to the classpath:

scala -classpath "$CLASSPATH":. CpuTest

Now I do not understand why that should be: the original CLASSPATH already includes the .class file.

1

There are 1 answers

1
WestCoastProjects On BEST ANSWER

I was misusing the

<path>/*

in the classpath: the wildcard only supports jar files, not .class files.