Consolidating Java and Scala in IJ

Source: Internet
Author: User

1, the first need to download Scala plug-ins, note that the plug-in version and the version of IJ closer.

: Https://plugins.jetbrains.com/plugin/1347-scala

2. You will then need to configure the plugin for compiling Scala code and some of Scala's dependency packages in the Maven pom file.

1<?xml version="1.0"encoding="UTF-8"?>2<project xmlns="http://maven.apache.org/POM/4.0.0"3Xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"4xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">5<modelVersion>4.0.0</modelVersion>6<groupId>com.hxy</groupId>7<artifactId>how2j</artifactId>8<version>1.0-snapshot</version>9 Ten<build> One<plugins> A<plugin> -<!--compiling Java code-- -<groupId>org.apache.maven.plugins</groupId> the<artifactId>maven-compiler-plugin</artifactId> -<version>3.2</version> -<configuration> -<source>1.8</source> +<target>1.8</target> -<encoding>utf-8</encoding> +</configuration> A<executions> at<execution> -<phase>compile</phase> -<goals> -<goal>compile</goal> -</goals> -</execution> in</executions> -</plugin> to<plugin> +<!--compiling Scala code-- -<groupId>net.alchim31.maven</groupId> the<artifactId>scala-maven-plugin</artifactId> *<version>3.2.1</version> $<executions>Panax Notoginseng<execution> -<id>scala-compile-first</id> the<phase>process-resources</phase> +<goals> A<goal>add-source</goal> the<goal>compile</goal> +</goals> -</execution> $</executions> $</plugin> -</plugins> -</build> the  -<dependencies>Wuyi<dependency> the<groupId>junit</groupId> -<artifactId>junit</artifactId> Wu<version>3.8.1</version> -<scope>test</scope> About</dependency> $  -<dependency> -<groupId>junit</groupId> -<artifactId>junit</artifactId> A<version>4.11</version> +</dependency> the  -<dependency> $<groupId>org.hibernate</groupId> the<artifactId>hibernate-validator</artifactId> the<version>4.3.2. Final</version> the</dependency> the  -<dependency> in<groupId>javax.validation</groupId> the<artifactId>validation-api</artifactId> the<version>1.1.0. Final</version> About</dependency> the  the<dependency> the<groupId>org.scala-lang</groupId> +<artifactId>scala-library</artifactId> -<version>2.10.1</version> the</dependency>Bayi  the<dependency> the<groupId>org.scala-lang</groupId> -<artifactId>scala-library</artifactId> -<version>2.12.1</version> the</dependency> the<dependency> the<groupId>org.scala-lang</groupId> the<artifactId>scala-compiler</artifactId> -<version>2.12.1</version> the</dependency> the<dependency> the<groupId>org.scala-lang</groupId>94<artifactId>scala-reflect</artifactId> the<version>2.12.1</version> the</dependency> the<dependency>98<groupId>org.scala-lang</groupId> About<artifactId>scala-actors</artifactId> -<version>2.11.8</version>101</dependency>102<dependency>103<groupId>org.scala-tools</groupId>104<artifactId>maven-scala-plugin</artifactId> the<version>2.15.2</version>106</dependency>107 108</dependencies>109</project>

3. The Java code is placed in the Java directory, and Scala code is placed under the Scala code. A simple Hello World example is as follows.

4. You can call Scala's code in Java code.

5. Summary

The JVM's platform is very powerful, whether it's Java, Kotlin or Scala, but the different languages on these JVMs can eventually be compiled into the same format. class files, and they support mutual invocation, so different scenarios we can

Select the most appropriate language, then call it in another language, and implement the entire software module with glue connection.

Consolidating Java and Scala in IJ

Related Article

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.