我无法弄清楚这个程序有什么问题?我使用较旧的scala版本(2.7),因为它与我正在使用的某些库兼容
这是一个我试图运行的简单程序。
使用scalac
和scala
命令,程序运行正常。
然而,在IntelliJ 14+上 - >当我create a new project
- > select the compiler (scala 2.7)
并尝试运行上述程序我在下面收到此错误
object SimpleClass {
def main(args: Array[String]) {
println("This is a simple Class")
}
}
错误输出。
为什么intelliJ会抛出ClassNotFoundException
?我已将该程序保存为SimpleClass.scala
/usr/lib/jvm/java-7-openjdk-i386/bin/java -Didea.launcher.port=7532 -Didea.launcher.bin.path=/home/tejesh/Downloads/idea-IC-141.1532.4/bin -Dfile.encoding=UTF-8 -classpath /usr/lib/jvm/java-7-openjdk-i386/jre/lib/javazic.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/management-agent.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/resources.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/rhino.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/charsets.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/jce.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/jsse.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/rt.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/compilefontconfig.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/localedata.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/zipfs.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/sunpkcs11.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/dnsns.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/java-atk-wrapper.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/sunjce_provider.jar:/usr/lib/jvm/java-7-openjdk-i386/jre/lib/ext/icedtea-sound.jar:/usr/local/share/scala-2.7.3/lib/scala-swing.jar:/usr/local/share/scala-2.7.3/lib/scala-library.jar:/home/tejesh/Downloads/idea-IC-141.1532.4/lib/idea_rt.jar com.intellij.rt.execution.application.AppMain SimpleClass
Exception in thread "main" java.lang.ClassNotFoundException: SimpleClass
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:122)
我已在SimpleClass
sources
的文件夹
答案 0 :(得分:2)
IntelliJ IDEA的最新Scala基于sbt。显然,此配置中不再支持Scala 2.7.3。如果您设置了一个项目,IntelliJ将为您提供(当您为SDK选择"下载"没有比Scala 2.8.0更早的版本)。如果手动选择2.7.3,则在尝试编译时会发生以下情况:
Error:scalac: Error: org.jetbrains.jps.incremental.scala.remote.ServerException
Error compiling sbt component 'compiler-interface-2.7.3.final-52.0'
at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1$$anonfun$apply$2.apply(AnalyzingCompiler.scala:145)
at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1$$anonfun$apply$2.apply(AnalyzingCompiler.scala:142)
at sbt.IO$.withTemporaryDirectory(IO.scala:285)
at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1.apply(AnalyzingCompiler.scala:142)
at
...
下一步是Scala 2.8.2,您可以获得:
Error:scalac: Parameter '-nobootcp' is not recognised by Scalac.
与当前的IntelliJ一起使用的最旧的Scala似乎是 2.9.0 。 (你必须使用Java 7而不是Java 8!)
解决方案是将降级IntelliJ IDEA 降级为仍然支持Scala 2.7.3(可能是IDEA 11?)的旧版本,或者只是使用Scala 2.9.3设置项目,但是手动编译(或使用终端的sbt )对2.7.3。
如果您拥有需要2.7.3的库的源代码,或许最好的选择是尝试使用当代版本的Scala(至少2.9.0)编译库。