且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Intellij Idea 11上运行scala代码?

更新时间:2022-05-20 02:42:37

安装了Scala插件


  • A。创建一个新项目,并在创建阶段选择Scala构面。它将创建Scala库lib和Scala编译器库并为您设置构面

  • A. Create a new project and select the Scala facet in the creation phase. It will create the Scala library lib and Scala compiler lib and setup the facet for you

B.如果你已经有一个项目。转到项目结构 - >模块,右键单击模块,然后转到添加构面并添加Scala构面。现在你需要添加scala-library.jar作为模块的库并进入Scala facet并将其指向包含scala-compiler.jar的库

B. If you already have a project. Go to Project Structure -> Modules and right click the module and go Add facet and add a Scala facet. Now you need to add scala-library.jar as a library of the module and go into the Scala facet and point it to a library containing scala-compiler.jar

更多信息

这是您的模块在项目设置下应该是什么样子

this is what your module should look like under project settings

选择Scala构面和这是你应该看到的(编译器的库名称是不重要的,只要它在库名称旁边说(版本xxx)

select the Scala facet and this is what you should see (Library name for the compiler is unimportant as long as it says (version xxx) next to the library name

这些是我的scala编译器库中的jar文件

these are the jar files in my scala-compiler lib

这些是我的scala-libra中的jar文件ry lib

and these are the jar files in my scala-library lib

通过这样的设置你应该能够在源目录中右键单击 - >新的Scala类(从下拉列表中选择对象)并添加

With everything setup like that you should be able to right click -> new Scala class (Select object from the dropdown) in a source directory and add

def main(args:Array[String]) {
   println("Hello world")
}

然后右键单击该类并选择Run Classnam.main(),IntelliJ将为您设置运行配置。

then right click on the class and select Run Classnam.main() and IntelliJ will setup a run configuration for you.