“错误:找不到主类 scala.tools.nsc.MainGenericRunner"在 Windows 中运行 Scala 时 [英] "error: can't find main class scala.tools.nsc.MainGenericRunner" when running scala in windows
问题描述
在为 windows 下载 scala 2.10.2 并运行 scala 后,我遇到了这样的错误:
after downloaded scala 2.10.2 for windows, and run scala I met such error:
"错误: scala.tools.nsc.MainGenericRunner"
这意味着错误:无法找到或加载主类 scala.tools.nsc.MainGenericRunner".于是查了一下scala.bat
的原因,发现了这样的功能:
which means "error: can't find or load main class scala.tools.nsc.MainGenericRunner". So I check the scala.bat
for reasons, and I found such function:
:set_home
set _BIN_DIR=
for %%i in (%~sf0) do set _BIN_DIR=%_BIN_DIR%%%~dpsi
echo in set_home: %_BIN_DIR%
set _SCALA_HOME=%_BIN_DIR%..
goto :eof
这个函数之后_SCALA_HOME变成了D:\program files\scala\files\scala\bin\..
,这显然是错误的.无论如何,在将 _SCALA_HOME 设置为正确路径后,错误已修复.然而,有谁知道%~sf0
和%%~dpsi
是什么意思以及这个函数真正想要做什么?谢谢!
After this function the _SCALA_HOME become D:\program files\scala\files\scala\bin\..
, which is obviously wrong. Anyway, after setting _SCALA_HOME to be right path the error fixed. However, do any one knows what %~sf0
and %%~dpsi
mean and what this function is really trying to do ?
Thank you!
谢谢@gourlaysama
thank you @gourlaysama
我终于找到了真正的原因:执行下面的代码,你可以看到结果是:
I finally found the real reason:execute the following code and you can see the result is :
for %%i in (%~sf0) do (
echo "%%"i is: %%i
echo sf0 is : %%~dpsi
set _BIN_DIR=%_BIN_DIR%%%~dpsi
)
输出:
"%"i is: D:\program
sf0 is : D:\
"%"i is: files\scala\bin\scala.bat
sf0 is : D:\program files\scala\bin\files\scala\bin\
所以故障是由program
files
之间的额外空间造成的!
so the malfunction is result from the extra space between program
files
!
推荐答案
那些奇怪的变量被称为参数扩展.它们允许您将变量解释为文件/目录的路径,并直接从该路径解析内容.
Those weird variables are called parameter extensions. they allow you to interpret a variable as a path to a file/directory and directly resolve things from that path.
例如,如果 %1
是文件 dir123456\file.txt
的路径,
For example, if %1
is a path to a file dir123456\file.txt
,
%~f1
是file.txt
的完全限定路径,%~p1
是包含目录dir123456
的路径,%~s1
是短名称格式的路径dir123~1\file.txt
,- 还有许多其他人...
%~f1
is the fully qualified path tofile.txt
,%~p1
is the path to the containing directorydir123456
,%~s1
is the path in short name formatdir123~1\file.txt
,- and many others...
此外,%0
始终设置为当前正在运行的脚本的路径.所以:
Also, %0
is always set to the path of the currently running script. So:
%~fs0
是到当前脚本的全限定路径,采用短名称格式,%%~dpsi
是将FOR
变量%%i
手动扩展为一个盘符 (d
code> 选项)后跟包含文件夹的路径(p
选项),采用短格式(s
选项).
%~fs0
is the fully qualified path, in short name format, to the current script,%%~dpsi
is the manual expansion of theFOR
variable%%i
to a drive letter (d
option) followed by the path the containing folder (p
option), in short format (s
option).
现在,这个看起来很奇怪的代码块是 KB833431 的一种解决方法,其中 %~dps0
命令不会不给你当前脚本文件夹的路径(短格式),尽管它应该.这已在 XP SP2 中修复.
Now, this weird looking block of code is a workaround for KB833431 in which the %~dps0
command does not give you the path to the folder of the current script (in short format) although it should. This was fixed in XP SP2.
它似乎是从 scala.bat
的完全限定路径手动重建到 scala bin
目录的完全限定路径,然后只是获取该目录的父目录,这应该是一个有效的 _SCALA_HOME
.
It seems to be reconstructing manually the fully qualified path to the scala bin
directory from the fully qualified path to scala.bat
, and then just getting that directory's parent, which should be a valid _SCALA_HOME
.
这篇关于“错误:找不到主类 scala.tools.nsc.MainGenericRunner"在 Windows 中运行 Scala 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!