feat:更新README
This commit is contained in:
@@ -11,7 +11,7 @@ Scala 学习笔记工程,记录 2026-09-08 线下课内容。
|
||||
|
||||
```
|
||||
scala_20260908/
|
||||
├── pom.xml # Maven 配置(仅声明 JDK 21,未配置 Scala 插件)
|
||||
├── pom.xml # Maven 配置:JDK 8 + scala-maven-plugin 4.8.1
|
||||
└── src/main/scala/
|
||||
├── Hello.scala # 入口:Hello world
|
||||
├── demo1/
|
||||
@@ -37,30 +37,44 @@ scala_20260908/
|
||||
|
||||
- JDK 8
|
||||
- Scala 2.11.12
|
||||
- IntelliJ IDEA(推荐,装 Scala 插件即可直接运行)
|
||||
- Maven(可选,配合 `pom.xml` 编译)
|
||||
|
||||
> 注意:当前 `pom.xml` 里 `<maven.compiler.source/target>` 还写着 21,跟实际环境对不上。
|
||||
> Scala 2.11.12 也不支持 JDK 9+,需要把 pom.xml 改成 JDK 8 并加上 `scala-maven-plugin`。
|
||||
> 否则直接用 IntelliJ 跑 `main` 最省事。
|
||||
- Maven 3.x(`pom.xml` 已配好 `scala-maven-plugin` 4.8.1)
|
||||
- IntelliJ IDEA(可选,装 Scala 插件即可直接运行)
|
||||
|
||||
## 运行方式
|
||||
|
||||
### IntelliJ(推荐)
|
||||
### 命令行(Maven)
|
||||
|
||||
1. 用 IDEA 打开本目录
|
||||
2. 等待 IDEA 识别为 Scala 项目(首次会提示装 Scala 插件)
|
||||
3. 打开任意 `.scala` 文件,右键 `Run 'XXX.main()'`
|
||||
先编译:
|
||||
|
||||
### 命令行(需要先配好 scala-maven-plugin)
|
||||
```bash
|
||||
mvn clean compile
|
||||
```
|
||||
|
||||
再跑某个入口(任选其一):
|
||||
|
||||
```bash
|
||||
mvn scala:run -DmainClass=Hello
|
||||
mvn scala:run -DmainClass=demo1.DemoVar
|
||||
mvn scala:run -DmainClass=demo2.DemoStr
|
||||
mvn scala:run -DmainClass=demo2.DemoVar2
|
||||
mvn scala:run -DmainClass=demo3.DemoOps
|
||||
mvn scala:run -DmainClass=practise1.Demo1VarAndVal
|
||||
mvn scala:run -DmainClass=practise1.Demo2Type
|
||||
mvn scala:run -DmainClass=practise1.Demo3StringInterpolation
|
||||
mvn scala:run -DmainClass=practise1.Demo4If
|
||||
mvn scala:run -DmainClass=practise1.Practise1
|
||||
mvn scala:run -DmainClass=practise1.Practise2
|
||||
mvn scala:run -DmainClass=practise1.Practise3
|
||||
mvn scala:run -DmainClass=practise1.Practise4
|
||||
mvn scala:run -DmainClass=practise1.Overall
|
||||
```
|
||||
|
||||
### IntelliJ
|
||||
|
||||
1. 用 IDEA 打开本目录
|
||||
2. 装 Scala 插件(首次会提示)
|
||||
3. 打开任意 `.scala` 文件,右键 `Run 'XXX.main()'`
|
||||
|
||||
## 重点速记
|
||||
|
||||
- `val` 定义常量(不能重新赋值),`var` 定义变量。**优先用 `val`**
|
||||
@@ -73,4 +87,3 @@ mvn scala:run -DmainClass=practise1.Overall
|
||||
## License
|
||||
|
||||
私有学习笔记,暂不外发。
|
||||
|
||||
|
||||
@@ -9,9 +9,48 @@
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<scala.version>2.11.12</scala.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- Scala 编译插件:让 mvn compile 也能编 .scala 源码 -->
|
||||
<plugin>
|
||||
<groupId>net.alchim31.maven</groupId>
|
||||
<artifactId>scala-maven-plugin</artifactId>
|
||||
<version>4.8.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>scala-compile-first</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>scala-test-compile</id>
|
||||
<phase>process-test-resources</phase>
|
||||
<goals>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- Java 编译插件:JDK 8 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
Reference in New Issue
Block a user