2021年08月25日 课堂笔记

Maven

配置

本地仓库位置

image-20210825091404428

镜像

阿里云镜像

image-20210825091441476

指定JDK版本

image-20210825091529800

不要用自带的maven

image-20210825091708640

image-20210825091738379

华为OD
要刷力扣

maven工程

image-20210825092929236

idea 微服务示例

更改maven位置

image-20210825093853608

idea创建微服务

image-20210825094426470

image-20210825094804099

提升级别

image-20210825094856419

主类所在的包下扫描,所以要把主类提升到上一级别。

image-20210825095338848

image-20210825095508947

优化:

image-20210825095536999

image-20210825095634472

maven打包

到项目对应的目录中,然后输入

1
mvn package

找到打包好的jar包

进入target目录:

1
cd .\target\

查看目录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
PS G:\dev2\idea_workspace\webdemo\target> ls


目录: G:\dev2\idea_workspace\webdemo\target


Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2021.08.25 10:06 classes
d----- 2021.08.25 10:05 generated-sources
d----- 2021.08.25 10:06 generated-test-sources
d----- 2021.08.25 10:16 maven-archiver
d----- 2021.08.25 10:15 maven-status
d----- 2021.08.25 10:16 surefire-reports
d----- 2021.08.25 10:06 test-classes
-a---- 2021.08.25 10:17 17345790 demo-0.0.1-SNAPSHOT.jar
-a---- 2021.08.25 10:16 3594 demo-0.0.1-SNAPSHOT.jar.original


PS G:\dev2\idea_workspace\webdemo\target>

可以看到有个jar文件:

1
demo-0.0.1-SNAPSHOT.jar

运行jar包

1
java -jar .\demo-0.0.1-SNAPSHOT.jar

运行成功效果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
PS G:\dev2\idea_workspace\webdemo\target> java -jar .\demo-0.0.1-SNAPSHOT.jar

. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.5.4)

2021-08-25 10:23:10.611 INFO 13044 --- [ main] com.example.DemoApplication : Starting DemoApplication v0.0.1-SNAPSHOT using Java 11.0.4 on DESKTOP-SH3MQPI with PID 13044 (G:\dev2\idea_workspace\webdemo\target\demo-0.0.1-SNAPSHOT.jar started by 18190 in G:\dev2\idea_workspace\webdemo\target)
2021-08-25 10:23:10.611 INFO 13044 --- [ main] com.example.DemoApplication : No active profile set, falling back to default profiles: default
2021-08-25 10:23:12.923 INFO 13044 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9000 (http)
2021-08-25 10:23:12.954 INFO 13044 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-08-25 10:23:12.954 INFO 13044 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.52]
2021-08-25 10:23:13.095 INFO 13044 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-08-25 10:23:13.095 INFO 13044 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2250 ms
2021-08-25 10:23:13.642 INFO 13044 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
2021-08-25 10:23:13.814 INFO 13044 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9000 (http) with context path ''
2021-08-25 10:23:13.829 INFO 13044 --- [ main] com.example.DemoApplication : Started DemoApplication in 4.687 seconds (JVM running for 5.481)

image-20210825095832386

浏览器即可访问

进入浏览器即可访问:

image-20210825102421351

image-20210825102439235