Hello IDEA

Time:2021-5-9

Scala-SBT

First, install the scala plug-in. SBT plug-in is available by default in version 13 +

Hello IDEA

Create a new project and select the scala project mode based on SBT

Hello IDEA

Next, choose JDK and SBT, Scala version

Hello IDEA

Click Finish to generate the following code structure diagram: where
The build. SBT file is similar to Maven’s POM. XML
In Src / main, Java, resources and scala will be created

Hello IDEA

Create a new Scala object. (or create a new Scala class, but in order to run in the idea, create a new object with the same name in the class)

Hello IDEA

Operation mode:

  1. Right click on Scala object to run your object name

  2. Run with SBT command

[email protected]:~/IdeaProjects$ cd scala-sbt/
[email protected]:~/IdeaProjects/scala-sbt$ ls
build.sbt  project  src  target
[email protected]:~/IdeaProjects/scala-sbt$ sbt
[info] Loading project definition from /home/hadoop/IdeaProjects/scala-sbt/project
[info] Set current project to scala-sbt (in build file:/home/hadoop/IdeaProjects/scala-sbt/)
> compile
[info] Updating {file:/home/hadoop/IdeaProjects/scala-sbt/}scala-sbt...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 3 Scala sources to /home/hadoop/IdeaProjects/scala-sbt/target/scala-2.10/classes...
[warn] there were 1 deprecation warning(s); re-run with -deprecation for details
[warn] one warning found
[success] Total time: 6 s, completed 2015-1-30 17:16:37
> run

Multiple main classes detected, select one to run:

 [1] com.zqh.akka.Pi
 [2] com.zqh.scala.HelloScala
 [3] com.zqh.akka.HelloAkka

Enter number: 1

[info] Running com.zqh.akka.Pi 

    Pi approximation:       3.1415926435897883
    Calculation time:   490 milliseconds
[success] Total time: 6 s, completed 2015-1-30 17:16:47
> 
  1. Running SBT with idea

Click the SBT console view and click the Green Run button to automatically run the SBT command

Hello IDEA

Jar packages that the project depends on:

Hello IDEA

Scala-Module

Create an empty project: codebase

Hello IDEA

In an empty project, you can create multiple modules in different languages. For example, Scala module. Note that there is no SBT option here!

Hello IDEA

Because it’s just a Scala module and only generates a SRC directory, there is no fixed code structure generated by SBT

Hello IDEA

Maven-Module

You can create a new Maven project in this codebase project

1. Click external libraries, and then new module. Don't add new module to existing modules
2. Be careful not to check create from archetype, otherwise it will not automatically generate Src / main / Java and other directories for you
3. The first step is not to create a new module in the existing module, so the parent interface of the new module is none

Hello IDEA

The code structure of Maven is Src / main / Java, Src / main / resources, and pom.xml in the root directory, which is used to load the third-party jar package

Hello IDEA

Gradle-Module

http://clojure.iteye.com/blog/2091723

mkdir gradle-demo && cd gradle-demo && vi build.gradle

apply plugin: 'idea'
apply plugin: 'scala'

task "createDirs" << {
    sourceSets*.scala.srcDirs*.each { it.mkdirs() }
    sourceSets*.resources.srcDirs*.each { it.mkdirs() }
}

repositories{
    mavenCentral()
    mavenLocal()
}

dependencies{
    compile "org.scala-lang:scala-library:2.10.4"
    compile "org.scala-lang:scala-compiler:2.10.4"
    compile "org.scala-lang:scala-reflect:2.10.4"
    testCompile "junit:junit:4.11"
}

task run(type: JavaExec, dependsOn: classes) {
    main = 'Main'
    classpath sourceSets.main.runtimeClasspath
    classpath configurations.runtime
}

gradle createDirs

:createDirs
BUILD SUCCESSFUL
Total time: 4.413 secs

In idea, import module, select the directory you just created

Hello IDEA

Hello IDEA

Hello IDEA

Clojure-module

Install the clojure plug-in La clojure

Create a clojure module: clojure demo

Hello IDEA

Hello IDEA

In helloclojure.clj, right-click run ‘helloclojure’, and the shortcut key is: Ctrl + Shift + F10

Hello IDEA

Or right click start clojure console, and the shortcut is Ctrl + Shift + D
This call is actually clojure’s repl, which is the same as executing Java – jar clojure. Jar on the command line

Hello IDEA

leiningen

Scala related plug-ins include SBT and scala. SBT creates sample code structure projects. Scala does not. Neither does La clojure plug-in
Clojure’s construction tool is leiningen
https://github.com/technomancy/leiningen
http://wiki.fnil.net/index.php?title=Leiningen%E6%95%99%E7%A8%8B%E4%B8…

More Tutorial:
http://blog.8thlight.com/colin-jones/2010/11/26/a-leiningen-tutorial.h…
https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md
http://ben.vandgrift.com/2013/03/13/clojure-hello-world.html

downloadhttps://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lei…Put the script under ~ / bin

mv lein.txt lein
chmod 755 lein

The first execution of lein will download leiningen.jar package. Later, it will be downloaded when it is executed again. Refer to the lein script to set lein_ Jar uses the existing jar

vi ~/.bashrc

export LEIN_JAR=/home/hadoop/.lein/self-installs/leiningen-2.5.0-standalone.jar
export PATH=$PATH:/home/hadoop/sh:/home/hadoop/bin
source ~/.bashrc

[email protected]:~/IdeaProjects/codebase$ lein new clojure-project
Generating a project called clojure-project based on the 'default' template.
The default template is intended for library projects, not applications.
To see other templates (app, plugin, etc), try `lein help new`.
[email protected]:~/IdeaProjects/codebase$ tree clojure-project/
clojure-project/
├── doc
│   └── intro.md
├── LICENSE
├── project.clj
├── README.md
├── resources
├── src
│   └── clojure_project
│       └── core.clj
└── test
    └── clojure_project
        └── core_test.clj

6 directories, 6 files

lein REPL

[email protected]:~/IdeaProjects/codebase/clojure-project$ lein repl
nREPL server started on port 59876 on host 127.0.0.1 - nrepl://127.0.0.1:59876
REPL-y 0.3.5, nREPL 0.2.6
Clojure 1.6.0
Java HotSpot(TM) 64-Bit Server VM 1.7.0_67-b01
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

user=> (+ 1 2)
3
user=> quit
Bye for now!
[email protected]:~/IdeaProjects/codebase/clojure-project$ lein run
No :main namespace specified in project.clj.

lein RUN

[email protected]:~/IdeaProjects/codebase/clojure-project$ cat project.clj
(defproject clojure-project "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.6.0"]]
  :main ^:skip-aot clojure-project.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}})

[email protected]:~/IdeaProjects/codebase/clojure-project$ cat src/clojure_project/core.clj 
(ns clojure-project.core)

(defn foo
  "I don't do a whole lot."
  [x]
  (println x "Hello, World!"))

(defn -main []
  (foo "zqh"))

[email protected]:~/IdeaProjects/codebase/clojure-project$ lein run
zqh Hello, World!

Idea and leiningen

http://clojure.iteye.com/blog/1740422 
http://www.cnblogs.com/devos/p/4201743.html