Scala Development Environment Configuration

Source: Internet
Author: User

Scala has no potential than groovy. Its syntax can be said to be newer than python, so some people cannot accept it. Scala is a functional and imperative object-oriented JVM-based programming language that can be directly executed on the console or terminal. The syntax is quite concise and straightforward. Scala is currently not very popular in China, but it has been used for some of the leading Google companies abroad, such as Android systems. The following three steps describe Scala's development environment.

Configure system environment variables

On the Windows platform, you can directly download the MSI installation file from the official website, provided that JDK has been installed in the system and JDK environment variables have been configured.

Environment variables are automatically added to the path during the default installation process. If you do not like the default method, you can add it yourself:

Scala_home: C: \ Program Files (x86) \ Scala \
Add % scala_home % \ bin after path

OK. Enter Scala-version check in the console.

Create a Scala project under intellij idea

Whether it is eclipse or idea, you need to add the corresponding plug-in to create the scala project. The development tool here is intellij idea. This tool is used as an example.

First, click File> Settings> plugins and search for Scala to install it directly. After installation, a prompt will be prompted to restart.

Click File> new project... click scala. There are two options: Non-SBT and SBT. SBT (simple build tool) uses Ivy as the library management tool. Similar to Maven, it can be downloaded at http://code.google.com/p/simple-build-tool/downloads/list. To avoid trouble, I will select non-SBT here.

If Scala environment variables have been configured, idea will find the scala compiler and class library in the existent library, right-click the project to create the corresponding package and class:

/** * @author Barudisshu */object HelloWorld {  /*    def main(args: Array[String]) {      println("Hello World!")    }  */  def main(args: Array[String]): Unit = {    System.out.println("Hello World!")  }}
Right-click to run or press the shortcut key Ctrl + Shift + F10 to output Hello World on the console! Create Scala under Maven

Built under Maven is a Maven project, and there is a module under the project. Therefore, Scala is actually equivalent to a plug-in maven. You only need to add the corresponding plug-in.

<Build> <finalname >$ {artifactid} </finalname> <plugins> <plugin> <! -- Build JDK --> <artifactid> Maven-compiler-plugin </artifactid> <configuration> <source >$ {JDK. version} </source> <target >$ {JDK. version }</Target> </configuration> </plugin> <! -- Make Maven take effect for independent java files --> <artifactid> Maven-surefire-plugin </artifactid> <configuration> <includes> <include> **/* tests. java </include> </Includes> </configuration> </plugin> <groupid> Org. scala-tools </groupid> <artifactid> Maven-Scala-plugin </artifactid> <executions> <execution> <goals> <goal> compile </goal> <goal> testcompile </goal> </goals> </execution> </executions> <configuration> <sourcedir> src/main/Java </sourcedir> <jvmargs> <jvmarg>-xms64m </jvmarg> <jvmarg>-xmx1024m </jvmarg> </jvmargs> </configuration> </plugin> </plugins> </build>

After the entry is added, intellij idea enters the read entry status. After the entry is read, the scala file can be created. However, after the scala file is created, it cannot be run because there is no compiler, therefore, add Scala dependencies to Maven as follows:

<dependency>    <groupId>org.scala-lang</groupId>    <artifactId>scala-library</artifactId>    <version>${scala.version}</version></dependency><dependency>    <groupId>org.scala-lang</groupId>    <artifactId>scala-reflect</artifactId>    <version>${scala.version}</version></dependency><dependency>    <groupId>org.scala-lang</groupId>    <artifactId>scala-compiler</artifactId>    <version>${scala.version}</version></dependency><dependency>    <groupId>org.scala-lang</groupId>    <artifactId>scala-swing</artifactId>    <version>${scala.version}</version></dependency>
OK. After matching, you can create a module to write Scala.

Scala compilation for the first time will be much slower than Java. It will eventually be compiled into a Class byte file and handed over to JVM for processing. In fact, it is also something that will not be changed, but it simplifies the development of programmers.



Scala Development Environment Configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.