I am able to compile scala programs using scalac in terminal but I get the warning.
Charless-Macintosh:src Charles$ scalac hello.scala
Charless-Macintosh:src Charles$ scala HelloWorld
No such file or class on classpath: HelloWorld
Is this to do with .profile
on scala. I'm pretty confused as to what is happening. Many thanks
The problem is that you have set the
CLASSPATH
environment variable.From
> man scalac
:When you have the
CLASSPATH
variable set, scala will not include the current directory in its search, you must explicitly add it. This is whyscala -cp . HelloWorld
works.To verify, perform
echo CLASSPATH
and it should give some non-empty string. Check your .bashrc/.zshrc files for anyexport CLASSPATH=...
and remove these lines.The current directory is typically not in the classpath by default. So you need to give explicitly:
This was also happening to me but I think the better solution is to modify the
CLASSPATH
variable to include the current directory in addition to what you already had. e.g.export CLASSPATH=.:$CLASSPATH
Now, you can simply use
scala HelloWorld
without that additional argument.