---------------------
Preface---------------------Project relationship and want to do data analysis and image display with Spark GRAPHX, but only if Spark;spark is based on Scala, Scala is Java based ... So, in the case of Spark GraphX, the technology stack should generally be like this: Spark GraphX----, Scala, Java Java has been so many years ... Let's just say that we started with the study of Scala. --------------------
Description--------------------1) The Java configuration is complete and the version is above 1.8, because Scala is based on Java, and the class file generated after compilation can be traveled to the JVM and called by Java. 2) IntelliJ idea installed complete (my version is: 2017.2.2) 3) Development environment: MacOS--------------------
Install, configure Scala--------------------
1. Install the Scala SDKFirst to http://www.scala-lang.org/download/download the compressed package Scala-2.12.4.tar and unzip. (You can also install the first Scala source file in IntelliJ idea, as prompted, as described in "Scala & IntelliJ Idea: Environment building, HelloWorld") Configuring Environment Variables: 1) vi/etc/ The profile is added at the end:Export scala_home=/users/yp-tc-m-2755/documents/software/scala-2.12.4export path= $PATH: $SCALA _home/binSave exit. 2) Enter the command to make it effective: Source/etc/profile 3) test (restart terminal if not in effect): $ scala-versionScala Code Runner version 2.12.4-Copyright 2002-2017, LAMP/EPFL and Lightbend, Inc.
2. Install the Scala pluginIntelliJ idea, Preferences, Plugins, Browse repositories ... (or in the IntelliJ idea welcome page, lower right corner click: configure->preferences) 1) In the search box input SCALA2) Select Scala3 in the list) click on the "Install" button in the right box (after installation is complete) --------------------
To Create a Java Web project--------------------
1. Create a Web project using the MAVEN frameworkMy choice is: Maven-archetype-webapp. Not for anything else, because a index.jsp is automatically created to test whether Tomcat starts properly ... The directory structure is probably like this: 2. Manually add Java,scala folder 1) in the main directory, create a new Java,scala folder, click File->project structure->modules Right-click the main folder, select "New Folder", Create the Java and Scala folders separately. 2) Select Java and Scala respectively, click on the button "Sources" above, so that the two folders are marked with the file is the source code.Otherwise, when you want to create the source file, right-click Java or Scala, there is no Java class and Scala class option in New->file.
3. Add dependency to Scalas in Pom.xml<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" ><modelVersion>4.0.0</modelVersion> <groupId>wangjun</groupId><artifactId>ScalaInJava</artifactId><packaging>war</packaging><version>1.0-SNAPSHOT</version> <name>scalainjava Maven webapp</name><url>http://maven.apache.org</url> <dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency> <dependency><groupId>org.scala-lang</groupId><artifactId>scala-library</artifactId><version>2.12.4</version></dependency><dependency><groupId>org.scala-lang</groupId><artifactId>scala-compiler</artifactId><version>2.12.4</version></dependency><dependency><groupId>org.scala-lang</groupId><artifactId>scala-reflect</artifactId><version>2.12.4</version></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.12</version></dependency><dependency><groupId>com.google.collections</groupId><artifactId>google-collections</artifactId><version>1.0</version></dependency></dependencies><build><finalName>ScalaInJava</finalName><plugins><plugin><groupId>org.scala-tools</groupId><artifactId>maven-scala-plugin</artifactId><version>2.15.2</version><executions><execution><goals><goal>compile</goal><goal>testCompile</goal></goals></execution></executions></plugin></plugins></build></project>Note: If you do not add <plugin>, errors will occur at compile time: no prefix ' Scala ' or no symbols found
4. Create the source file:1) Create the Hellojava.java in the Java directory with the following content:Public class Hellojava {Public static void Main (string[] args) {System.out.println ("Hello:java");Helloscala Helloscala = new Helloscala ();Helloscala.sayhello ("My first scala!");}}2) Create Helloscala.scala in the Scala directory with the following content:class Helloscala {def SayHello (x:string): Unit = {println ("Hello," + x)}}As you can see, the Helloscala to function SayHello is called in Hellojava.
5. Run:In the Hellojava.java edit box anywhere, right-click, select: Run ' Hellojava.main () ' Console output: OK, you can start the Scala tour! --------------------Reference--------------------1) Scala IntelliJ idea Environment building and compiling, packaging https://www.cnblogs.com/yjmyzz/p/ 4694219.HTML2) IntelliJ idea + maven to create a Java Web Project https://www.cnblogs.com/davidgu/p/5887938. HTML3) using IntelliJ to create your first MAVEN project http://blog.csdn.net/zhangxing52077/article/details/695258324) maven Three kinds of archetype instructions http://blog.csdn.net/cx1110162/article/details/78297654
Scala & IntelliJ Idea Environment Build upgrade: Call Scala's HelloWorld in Java