如何在Intellij Idea 11上运行scala代码? [英] How to run scala code on Intellij Idea 11?

查看:210
本文介绍了如何在Intellij Idea 11上运行scala代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是intellij想法的新手,我决定转移,因为我发现eclipse上的scala插件非常烦人。
但是,我听说非常好的intellij想法看起来很难使用。
我查看了开始使用scala插件页面但是找不到针对scala的intellij idea 11的最新版本轻量级ide的文档。

I am new to intellij idea and I decided to shift because I found the scala plugin on eclipse to be annoyingly buggy. But, intellij idea, which I have heard to be very good, looks difficult to use. I looked through the getting started with scala plugin page but couldn't find documentation specific to the latest version of lightweight ide of intellij idea 11 for scala.

我创建了一个项目并创建了一个hello world对象斯卡拉但我无法运行它。
在尝试运行它时,它显示了scala解释器(在表达式中键入以对它们进行求值)。
我不完全理解在项目结构中要做什么更改才能运行scala代码。截至目前,我添加了jsdk指向我的$ JAVA_HOME并且还添加了scala库。 scala插件也在使用语法高亮等等。

I have created a project and made a hello world object in scala but I am not able to run it. On trying to run it, it shows the scala interpreter (type in expressions to get them evaluated). I don't exactly understand what changes to make in the project structure to be able to run scala code. As of now, i added the jsdk to point to my $JAVA_HOME and the scala library is also added. The scala plugin is also working in that syntax highlighting etc is fine.

intellij想法用户界面也不是很友好,我不知道如何运行代码。我应该添加哪些模块?此外,编译的scala代码是否与jvm一起运行?
我会感激任何帮助过的人..我一直在推迟编写scala代码,因为我无法找到IDE。

The intellij idea user interface is also not very friendly and I don't get how to run the code. What modules am I supposed to add? Also, does compiled scala code run with jvm? I'll be grateful to anyone who helps out.. I have been putting off writing scala code because I am not able to find THE IDE.

EDIT :感谢所有的帮助!我现在能够运行一个基本的scala程序。我正在尝试添加外部罐子。什么是相当于做项目右键单击 - >配置构建路径 - >在eclipse中添加外部jar文件?我尝试在项目结构中的模块选项卡下添加依赖项。它正在添加jar文件,但不知何故仍然无法识别jar文件中的类。

Thanks for all the help! I am now able to run a basic scala program. I am trying to add external jars. What is the equivalent of doing Project right click-> Configure Build Path -> adding external jar files in eclipse? I tried adding "dependencies " under modules tab in project structure. It's adding the jar files but somehow the classes in the jar files are not still recognised.

推荐答案

安装了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.

这篇关于如何在Intellij Idea 11上运行scala代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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