为什么在IntelliJ 14+上运行简单的Scala程序时出现ClassNotFoundException? [英] Why do i get a ClassNotFoundException on running a simple scala program on IntelliJ 14+?

查看:161
本文介绍了为什么在IntelliJ 14+上运行简单的Scala程序时出现ClassNotFoundException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚该程序出了什么问题?我使用的是旧版的Scala(2.7),因为它与我正在使用的某些库兼容

I'm unable to figure out what is wrong with this program? I'm using an older verison of scala (2.7) because its compatible with certain libraries i'm using

这是我尝试运行的简单程序.

Here is a simple program i'm attempting to run.

使用scalacscala命令,程序可以正常运行.

The program runs fine using scalac and scala commands.

但是在IntelliJ 14+->上,当我create a new project-> select the compiler (scala 2.7)并尝试运行上述程序时,我在下面收到此错误

However on IntelliJ 14+ -> when i create a new project -> select the compiler (scala 2.7) and try to run the above program i get this error below

object SimpleClass {
  def main(args: Array[String]) {
    println("This is a simple Class")
  }
}

错误输出.

为什么intelliJ抛出ClassNotFoundException?我已将该程序另存为SimpleClass.scala

Why does intelliJ throw the ClassNotFoundException? I've saved the program as 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)

我已经在sources

这是完整的程序在这里

This is the full program here

推荐答案

IntelliJ IDEA的最新Scala基于sbt.显然,此配置不再支持Scala 2.7.3.如果设置项目,则IntelliJ将为您(当您为SDK选择下载"时)不提供Scala 2.8.0之前的版本.如果您手动选择2.7.3,则在尝试编译时会发生以下情况:

Recent Scala for IntelliJ IDEA is based on sbt. Apparently Scala 2.7.3 is not supported any longer in this configuration. If you set up a project, IntelliJ will offer you (when you select "Download" for the SDK) no version older than Scala 2.8.0. If you manually select 2.7.3, the following happens when you try to compile:

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,您将获得:

The next step is Scala 2.8.2, for which you get:

Error:scalac: Parameter '-nobootcp' is not recognised by Scalac.

似乎与当前IntelliJ兼容的最旧的Scala是 2.9.0 . (为此,您必须使用Java 7而不是Java 8!)

It seems the oldest Scala that works with the current IntelliJ is 2.9.0. (You have to use Java 7 and not Java 8 for this!)

解决方案是将IntelliJ IDEA降级到仍支持Scala 2.7.3(也许是IDEA 11?)的旧版本,或者只是使用Scala 2.9.3设置项目,但是相对于2.7.3 手动编译(或使用终端的sbt ).

The solution would be to downgrade IntelliJ IDEA to an old version that still supports Scala 2.7.3 (perhaps IDEA 11?), or to simply set up the project with Scala 2.9.3, but compile instead manually (or using sbt from the terminal) against 2.7.3.

如果您有需要2.7.3的库的源代码,也许最好的选择是尝试使用现代版本的Scala(至少为2.9.0)编译该库.

If you have the source to the library that requires 2.7.3, perhaps the best option is to try to compile the library with contemporary versions of Scala (at least 2.9.0).

这篇关于为什么在IntelliJ 14+上运行简单的Scala程序时出现ClassNotFoundException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆