-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools-dev-maven.html
1137 lines (1123 loc) · 346 KB
/
tools-dev-maven.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="zh-CN" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Maven | 广度和深度</title>
<meta name="description" content="整理和记录代码学习的笔记">
<link rel="preload stylesheet" href="/assets/style.66b7dec6.css" as="style">
<script type="module" src="/assets/app.f6aa04bd.js"></script>
<link rel="preload" href="/assets/inter-roman-latin.2ed14f66.woff2" as="font" type="font/woff2" crossorigin="">
<link rel="modulepreload" href="/assets/chunks/framework.027d2da0.js">
<link rel="modulepreload" href="/assets/chunks/theme.98d176af.js">
<link rel="modulepreload" href="/assets/tools-dev-maven.md.e0a81f73.lean.js">
<link rel="icon" href="./favicon.ico">
<script id="check-dark-light">(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"dark",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.classList.add("dark")})();</script>
<script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
</head>
<body>
<div id="app"><div class="Layout" data-v-8692e0c2><!--[--><!--]--><!--[--><span tabindex="-1" data-v-7da17955></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-7da17955> Skip to content </a><!--]--><!----><header class="VPNav" data-v-8692e0c2 data-v-bcf310a9><div class="VPNavBar has-sidebar" data-v-bcf310a9 data-v-7192d962><div class="container" data-v-7192d962><div class="title" data-v-7192d962><div class="VPNavBarTitle has-sidebar" data-v-7192d962 data-v-56d4391f><a class="title" href="/" data-v-56d4391f><!--[--><!--]--><!--[--><img class="VPImage logo" src="./logo.jpg" alt data-v-506001e8><!--]--><!--[-->Coder<!--]--><!--[--><!--]--></a></div></div><div class="content" data-v-7192d962><div class="curtain" data-v-7192d962></div><div class="content-body" data-v-7192d962><!--[--><!--]--><div class="VPNavBarSearch search" data-v-7192d962><!--[--><!----><div id="local-search"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><svg class="DocSearch-Search-Icon" width="20" height="20" viewBox="0 0 20 20" aria-label="search icon"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-7192d962 data-v-359face2><span id="main-nav-aria-label" class="visually-hidden" data-v-359face2>Main Navigation</span><!--[--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-359face2 data-v-bb4a2dc7><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-bb4a2dc7><span class="text" data-v-bb4a2dc7><!----><span data-v-bb4a2dc7>♎语言</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-bb4a2dc7><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-bb4a2dc7><div class="VPMenu" data-v-bb4a2dc7 data-v-5d7a6046><div class="items" data-v-5d7a6046><!--[--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/lang-java.html" data-v-b6a76a69><!--[-->1️⃣ Java<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/lang-python.html" data-v-b6a76a69><!--[-->2️⃣ Python<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/lang-scala.html" data-v-b6a76a69><!--[-->3️⃣ Scala<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/lang-groovy.html" data-v-b6a76a69><!--[-->4️⃣ Groovy<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-359face2 data-v-bb4a2dc7><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-bb4a2dc7><span class="text" data-v-bb4a2dc7><!----><span data-v-bb4a2dc7>☯️算法</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-bb4a2dc7><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-bb4a2dc7><div class="VPMenu" data-v-bb4a2dc7 data-v-5d7a6046><div class="items" data-v-5d7a6046><!--[--><!--[--><div class="VPMenuGroup" data-v-5d7a6046 data-v-2d40012a><p class="title" data-v-2d40012a>算法篇</p><!--[--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫代码规范<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫设计模式<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫数据结构<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫源码解读<!--]--></a></div><!--]--><!--]--></div><!--]--><!--[--><div class="VPMenuGroup" data-v-5d7a6046 data-v-2d40012a><p class="title" data-v-2d40012a>并发篇</p><!--[--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫JVM<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫并发编程<!--]--></a></div><!--]--><!--]--></div><!--]--><!--[--><div class="VPMenuGroup" data-v-5d7a6046 data-v-2d40012a><p class="title" data-v-2d40012a>设计篇</p><!--[--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫系统设计<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫数仓理论<!--]--></a></div><!--]--><!--]--></div><!--]--><!--[--><div class="VPMenuGroup" data-v-5d7a6046 data-v-2d40012a><p class="title" data-v-2d40012a>职业篇</p><!--[--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫方向导航<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫职业规划<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫面试准备<!--]--></a></div><!--]--><!--]--></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-359face2 data-v-bb4a2dc7><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-bb4a2dc7><span class="text" data-v-bb4a2dc7><!----><span data-v-bb4a2dc7>♈前端</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-bb4a2dc7><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-bb4a2dc7><div class="VPMenu" data-v-bb4a2dc7 data-v-5d7a6046><div class="items" data-v-5d7a6046><!--[--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫HTML<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫CSS<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫JavaScript<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫JQuery<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫NodeJS<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Vue<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫React<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫小程序<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-359face2 data-v-bb4a2dc7><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-bb4a2dc7><span class="text" data-v-bb4a2dc7><!----><span data-v-bb4a2dc7>🔯微服务</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-bb4a2dc7><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-bb4a2dc7><div class="VPMenu" data-v-bb4a2dc7 data-v-5d7a6046><div class="items" data-v-5d7a6046><!--[--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫RPC<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Spring<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Spring MVC<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Spring Boot<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Spring Cloud<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Spring Cloud Alibaba<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Service Mesh<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-359face2 data-v-bb4a2dc7><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-bb4a2dc7><span class="text" data-v-bb4a2dc7><!----><span data-v-bb4a2dc7>⚧️数据存储</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-bb4a2dc7><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-bb4a2dc7><div class="VPMenu" data-v-bb4a2dc7 data-v-5d7a6046><div class="items" data-v-5d7a6046><!--[--><!--[--><div class="VPMenuGroup" data-v-5d7a6046 data-v-2d40012a><p class="title" data-v-2d40012a>SQL数据库</p><!--[--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫MySQL<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Oracle<!--]--></a></div><!--]--><!--]--></div><!--]--><!--[--><div class="VPMenuGroup" data-v-5d7a6046 data-v-2d40012a><p class="title" data-v-2d40012a>NoSQL数据库</p><!--[--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Redis<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫MongoDB<!--]--></a></div><!--]--><!--]--></div><!--]--><!--[--><div class="VPMenuGroup" data-v-5d7a6046 data-v-2d40012a><p class="title" data-v-2d40012a>NewSQL数据库</p><!--[--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫TiDB<!--]--></a></div><!--]--><!--]--></div><!--]--><!--[--><div class="VPMenuGroup" data-v-5d7a6046 data-v-2d40012a><p class="title" data-v-2d40012a>ORM框架</p><!--[--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Mybatis<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Mybatis Plus<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Spring Data JPA<!--]--></a></div><!--]--><!--]--></div><!--]--><!--[--><div class="VPMenuGroup" data-v-5d7a6046 data-v-2d40012a><p class="title" data-v-2d40012a>消息中间件</p><!--[--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Active MQ<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫RabbitMQ<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫RocketMQ<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Kafka<!--]--></a></div><!--]--><!--]--></div><!--]--><!--[--><div class="VPMenuGroup" data-v-5d7a6046 data-v-2d40012a><p class="title" data-v-2d40012a>文件存储</p><!--[--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫FastDFS<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Ceph<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫HDFS<!--]--></a></div><!--]--><!--]--></div><!--]--><!--[--><div class="VPMenuGroup" data-v-5d7a6046 data-v-2d40012a><p class="title" data-v-2d40012a>搜索引擎</p><!--[--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Lucene<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Solr<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫ElasticSearch<!--]--></a></div><!--]--><!--]--></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-359face2 data-v-bb4a2dc7><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-bb4a2dc7><span class="text" data-v-bb4a2dc7><!----><span data-v-bb4a2dc7>☸️DevOps</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-bb4a2dc7><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-bb4a2dc7><div class="VPMenu" data-v-bb4a2dc7 data-v-5d7a6046><div class="items" data-v-5d7a6046><!--[--><!--[--><div class="VPMenuGroup" data-v-5d7a6046 data-v-2d40012a><p class="title" data-v-2d40012a>部署</p><!--[--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/devops-deploy-tomcat.html" data-v-b6a76a69><!--[-->Tomcat<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/devops-deploy-tomcat.html" data-v-b6a76a69><!--[-->🚫Linux<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/devops-deploy-shell.html" data-v-b6a76a69><!--[-->Shell<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/devops-deploy-tomcat.html" data-v-b6a76a69><!--[-->🚫Nginx<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/devops-deploy-tomcat.html" data-v-b6a76a69><!--[-->🚫Linux<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/devops-deploy-tomcat.html" data-v-b6a76a69><!--[-->🚫LVS+Keepalived<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/devops-deploy-tomcat.html" data-v-b6a76a69><!--[-->🚫OpenResty+Kong<!--]--></a></div><!--]--><!--]--></div><!--]--><!--[--><div class="VPMenuGroup" data-v-5d7a6046 data-v-2d40012a><p class="title" data-v-2d40012a>容器</p><!--[--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Docker<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Kubernates<!--]--></a></div><!--]--><!--]--></div><!--]--><!--[--><div class="VPMenuGroup" data-v-5d7a6046 data-v-2d40012a><p class="title" data-v-2d40012a>云服务器</p><!--[--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫IaaS<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫UCloud<!--]--></a></div><!--]--><!--]--></div><!--]--><!--[--><div class="VPMenuGroup" data-v-5d7a6046 data-v-2d40012a><p class="title" data-v-2d40012a>持续集成</p><!--[--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Jenkins<!--]--></a></div><!--]--><!--]--></div><!--]--><!--[--><div class="VPMenuGroup" data-v-5d7a6046 data-v-2d40012a><p class="title" data-v-2d40012a>监控工具</p><!--[--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Arthas<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Zabbix<!--]--></a></div><!--]--><!--]--></div><!--]--><!--[--><div class="VPMenuGroup" data-v-5d7a6046 data-v-2d40012a><p class="title" data-v-2d40012a>链路追踪</p><!--[--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Sleuth+Zipkin<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫Skywalking<!--]--></a></div><!--]--><!--]--></div><!--]--><!--[--><div class="VPMenuGroup" data-v-5d7a6046 data-v-2d40012a><p class="title" data-v-2d40012a>性能压测</p><!--[--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫JMeter<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-2d40012a data-v-b6a76a69><a class="VPLink link" href="/#" data-v-b6a76a69><!--[-->🚫全链路压测<!--]--></a></div><!--]--><!--]--></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-359face2 data-v-bb4a2dc7><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-bb4a2dc7><span class="text" data-v-bb4a2dc7><!----><span data-v-bb4a2dc7>✝️工具</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-bb4a2dc7><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-bb4a2dc7><div class="VPMenu" data-v-bb4a2dc7 data-v-5d7a6046><div class="items" data-v-5d7a6046><!--[--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/tools-soft.html" data-v-b6a76a69><!--[-->软性办公工具<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/tools-vcs.html" data-v-b6a76a69><!--[-->版本控制工具<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/tools-dev.html" data-v-b6a76a69><!--[-->包管理工具<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/tools-dev.html" data-v-b6a76a69><!--[-->项目构建工具<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/tools-dev.html" data-v-b6a76a69><!--[-->编程工具<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/tools-dev.html" data-v-b6a76a69><!--[-->数据库管理<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/tools-dev.html" data-v-b6a76a69><!--[-->虚拟机工具<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/tools-dev.html" data-v-b6a76a69><!--[-->SSH工具<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/tools-dev.html" data-v-b6a76a69><!--[-->调试工具<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-5d7a6046 data-v-b6a76a69><a class="VPLink link" href="/tools-dev.html" data-v-b6a76a69><!--[-->压测工具<!--]--></a></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-7192d962 data-v-5c7f08f3><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="toggle dark mode" aria-checked="false" data-v-5c7f08f3 data-v-f44e5024 data-v-23c4cb6c><span class="check" data-v-23c4cb6c><span class="icon" data-v-23c4cb6c><!--[--><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="sun" data-v-f44e5024><path d="M12,18c-3.3,0-6-2.7-6-6s2.7-6,6-6s6,2.7,6,6S15.3,18,12,18zM12,8c-2.2,0-4,1.8-4,4c0,2.2,1.8,4,4,4c2.2,0,4-1.8,4-4C16,9.8,14.2,8,12,8z"></path><path d="M12,4c-0.6,0-1-0.4-1-1V1c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,3.6,12.6,4,12,4z"></path><path d="M12,24c-0.6,0-1-0.4-1-1v-2c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,23.6,12.6,24,12,24z"></path><path d="M5.6,6.6c-0.3,0-0.5-0.1-0.7-0.3L3.5,4.9c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C6.2,6.5,5.9,6.6,5.6,6.6z"></path><path d="M19.8,20.8c-0.3,0-0.5-0.1-0.7-0.3l-1.4-1.4c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C20.3,20.7,20,20.8,19.8,20.8z"></path><path d="M3,13H1c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S3.6,13,3,13z"></path><path d="M23,13h-2c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S23.6,13,23,13z"></path><path d="M4.2,20.8c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C4.7,20.7,4.5,20.8,4.2,20.8z"></path><path d="M18.4,6.6c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C18.9,6.5,18.6,6.6,18.4,6.6z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="moon" data-v-f44e5024><path d="M12.1,22c-0.3,0-0.6,0-0.9,0c-5.5-0.5-9.5-5.4-9-10.9c0.4-4.8,4.2-8.6,9-9c0.4,0,0.8,0.2,1,0.5c0.2,0.3,0.2,0.8-0.1,1.1c-2,2.7-1.4,6.4,1.3,8.4c2.1,1.6,5,1.6,7.1,0c0.3-0.2,0.7-0.3,1.1-0.1c0.3,0.2,0.5,0.6,0.5,1c-0.2,2.7-1.5,5.1-3.6,6.8C16.6,21.2,14.4,22,12.1,22zM9.3,4.4c-2.9,1-5,3.6-5.2,6.8c-0.4,4.4,2.8,8.3,7.2,8.7c2.1,0.2,4.2-0.4,5.8-1.8c1.1-0.9,1.9-2.1,2.4-3.4c-2.5,0.9-5.3,0.5-7.5-1.1C9.2,11.4,8.1,7.7,9.3,4.4z"></path></svg><!--]--></span></span></button></div><!----><div class="VPFlyout VPNavBarExtra extra" data-v-7192d962 data-v-4a4a2081 data-v-bb4a2dc7><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-bb4a2dc7><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="icon" data-v-bb4a2dc7><circle cx="12" cy="12" r="2"></circle><circle cx="19" cy="12" r="2"></circle><circle cx="5" cy="12" r="2"></circle></svg></button><div class="menu" data-v-bb4a2dc7><div class="VPMenu" data-v-bb4a2dc7 data-v-5d7a6046><!----><!--[--><!--[--><!----><div class="group" data-v-4a4a2081><div class="item appearance" data-v-4a4a2081><p class="label" data-v-4a4a2081>深浅模式</p><div class="appearance-action" data-v-4a4a2081><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="toggle dark mode" aria-checked="false" data-v-4a4a2081 data-v-f44e5024 data-v-23c4cb6c><span class="check" data-v-23c4cb6c><span class="icon" data-v-23c4cb6c><!--[--><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="sun" data-v-f44e5024><path d="M12,18c-3.3,0-6-2.7-6-6s2.7-6,6-6s6,2.7,6,6S15.3,18,12,18zM12,8c-2.2,0-4,1.8-4,4c0,2.2,1.8,4,4,4c2.2,0,4-1.8,4-4C16,9.8,14.2,8,12,8z"></path><path d="M12,4c-0.6,0-1-0.4-1-1V1c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,3.6,12.6,4,12,4z"></path><path d="M12,24c-0.6,0-1-0.4-1-1v-2c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,23.6,12.6,24,12,24z"></path><path d="M5.6,6.6c-0.3,0-0.5-0.1-0.7-0.3L3.5,4.9c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C6.2,6.5,5.9,6.6,5.6,6.6z"></path><path d="M19.8,20.8c-0.3,0-0.5-0.1-0.7-0.3l-1.4-1.4c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C20.3,20.7,20,20.8,19.8,20.8z"></path><path d="M3,13H1c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S3.6,13,3,13z"></path><path d="M23,13h-2c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S23.6,13,23,13z"></path><path d="M4.2,20.8c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C4.7,20.7,4.5,20.8,4.2,20.8z"></path><path d="M18.4,6.6c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C18.9,6.5,18.6,6.6,18.4,6.6z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="moon" data-v-f44e5024><path d="M12.1,22c-0.3,0-0.6,0-0.9,0c-5.5-0.5-9.5-5.4-9-10.9c0.4-4.8,4.2-8.6,9-9c0.4,0,0.8,0.2,1,0.5c0.2,0.3,0.2,0.8-0.1,1.1c-2,2.7-1.4,6.4,1.3,8.4c2.1,1.6,5,1.6,7.1,0c0.3-0.2,0.7-0.3,1.1-0.1c0.3,0.2,0.5,0.6,0.5,1c-0.2,2.7-1.5,5.1-3.6,6.8C16.6,21.2,14.4,22,12.1,22zM9.3,4.4c-2.9,1-5,3.6-5.2,6.8c-0.4,4.4,2.8,8.3,7.2,8.7c2.1,0.2,4.2-0.4,5.8-1.8c1.1-0.9,1.9-2.1,2.4-3.4c-2.5,0.9-5.3,0.5-7.5-1.1C9.2,11.4,8.1,7.7,9.3,4.4z"></path></svg><!--]--></span></span></button></div></div></div><!----><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-7192d962 data-v-9cc97dbb><span class="container" data-v-9cc97dbb><span class="top" data-v-9cc97dbb></span><span class="middle" data-v-9cc97dbb></span><span class="bottom" data-v-9cc97dbb></span></span></button></div></div></div></div><!----></header><div class="VPLocalNav reached-top" data-v-8692e0c2 data-v-a8f7ff89><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-a8f7ff89><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="menu-icon" data-v-a8f7ff89><path d="M17,11H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h14c0.6,0,1,0.4,1,1S17.6,11,17,11z"></path><path d="M21,7H3C2.4,7,2,6.6,2,6s0.4-1,1-1h18c0.6,0,1,0.4,1,1S21.6,7,21,7z"></path><path d="M21,15H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h18c0.6,0,1,0.4,1,1S21.6,15,21,15z"></path><path d="M17,19H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h14c0.6,0,1,0.4,1,1S17.6,19,17,19z"></path></svg><span class="menu-text" data-v-a8f7ff89>菜单</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-a8f7ff89 data-v-a050d324><button data-v-a050d324>返回顶部</button><!----></div></div><aside class="VPSidebar" data-v-8692e0c2 data-v-cde32d1c><div class="curtain" data-v-cde32d1c></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-cde32d1c><span class="visually-hidden" id="sidebar-aria-label" data-v-cde32d1c> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="group" data-v-cde32d1c><section class="VPSidebarItem level-0 collapsible collapsed" data-v-cde32d1c data-v-1f85ec84><div class="item" role="button" tabindex="0" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><h2 class="text" data-v-1f85ec84>软性办公</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-1f85ec84><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-1f85ec84><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-1f85ec84><!--[--><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-soft-baidupan.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>百度网盘</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-soft-foxit.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>福昕阅读器</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-soft-calibre.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Calibre</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-soft-chrome.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Chrome</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-soft-cmder.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Cmder</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-soft-evernote.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Evernote</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-soft-nodepad.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Nodepad</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-soft-office.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Office</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-soft-potplayer.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>PotPlayer</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-soft-snipaste.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Snipaste</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-soft-sublimetext.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>SublimeText</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-soft-typora.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Typora</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-soft-tizi.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>科学上网</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-soft-xmind.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Xmind</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-soft-7zip.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>7zip</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-soft-windows.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Windows</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-soft-markdown.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Markdown</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-cde32d1c><section class="VPSidebarItem level-0 collapsible collapsed" data-v-cde32d1c data-v-1f85ec84><div class="item" role="button" tabindex="0" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><h2 class="text" data-v-1f85ec84>版本管理</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-1f85ec84><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-1f85ec84><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-1f85ec84><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-1f85ec84 data-v-1f85ec84><div class="item" role="button" tabindex="0" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><h3 class="text" data-v-1f85ec84>Git</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-1f85ec84><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-1f85ec84><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-1f85ec84><!--[--><div class="VPSidebarItem level-2 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-vcs-git.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Git</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-vcs-gogs.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Gogs</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-vcs-gitee.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Gitee</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-vcs-github.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Github</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-vcs-gitlib.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>GitLib</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-vcs-gitflow.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>GitFlow</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-vcs-svn.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Svn</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-cde32d1c><section class="VPSidebarItem level-0 collapsible collapsed" data-v-cde32d1c data-v-1f85ec84><div class="item" role="button" tabindex="0" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><h2 class="text" data-v-1f85ec84>包管理工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-1f85ec84><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-1f85ec84><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-1f85ec84><!--[--><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-dev-nvm.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>NVM</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-cde32d1c><section class="VPSidebarItem level-0 collapsible collapsed" data-v-cde32d1c data-v-1f85ec84><div class="item" role="button" tabindex="0" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><h2 class="text" data-v-1f85ec84>项目构建</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-1f85ec84><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-1f85ec84><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-1f85ec84><!--[--><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-dev-maven.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Maven</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-dev-gradle.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Gradle</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-cde32d1c><section class="VPSidebarItem level-0 collapsible collapsed" data-v-cde32d1c data-v-1f85ec84><div class="item" role="button" tabindex="0" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><h2 class="text" data-v-1f85ec84>编程工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-1f85ec84><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-1f85ec84><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-1f85ec84><!--[--><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-dev-idea.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>IDEA</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-dev-vscode.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>VsCode</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-dev-pycharm.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>PyCharm</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-cde32d1c><section class="VPSidebarItem level-0 collapsible collapsed" data-v-cde32d1c data-v-1f85ec84><div class="item" role="button" tabindex="0" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><h2 class="text" data-v-1f85ec84>数据库管理</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-1f85ec84><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-1f85ec84><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-1f85ec84><!--[--><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-dev-navicat.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Navicat</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-cde32d1c><section class="VPSidebarItem level-0 collapsible collapsed" data-v-cde32d1c data-v-1f85ec84><div class="item" role="button" tabindex="0" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><h2 class="text" data-v-1f85ec84>虚拟机工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-1f85ec84><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-1f85ec84><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-1f85ec84><!--[--><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-dev-vmware.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>VMware</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-cde32d1c><section class="VPSidebarItem level-0 collapsible collapsed" data-v-cde32d1c data-v-1f85ec84><div class="item" role="button" tabindex="0" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><h2 class="text" data-v-1f85ec84>SSH工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-1f85ec84><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-1f85ec84><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-1f85ec84><!--[--><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-dev-ssh.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>SSH工具</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-cde32d1c><section class="VPSidebarItem level-0 collapsible collapsed" data-v-cde32d1c data-v-1f85ec84><div class="item" role="button" tabindex="0" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><h2 class="text" data-v-1f85ec84>调试工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-1f85ec84><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-1f85ec84><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-1f85ec84><!--[--><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-dev-postman.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>Postman</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-cde32d1c><section class="VPSidebarItem level-0 collapsible collapsed" data-v-cde32d1c data-v-1f85ec84><div class="item" role="button" tabindex="0" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><h2 class="text" data-v-1f85ec84>压测工具</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-1f85ec84><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-1f85ec84><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-1f85ec84><!--[--><div class="VPSidebarItem level-1 is-link" data-v-1f85ec84 data-v-1f85ec84><div class="item" data-v-1f85ec84><div class="indicator" data-v-1f85ec84></div><a class="VPLink link link" href="/tools-dev-jmeter.html" data-v-1f85ec84><!--[--><p class="text" data-v-1f85ec84>JMeter</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-8692e0c2 data-v-87044f80><div class="VPDoc has-sidebar has-aside" data-v-87044f80 data-v-e970bbc0><!--[--><!--]--><div class="container" data-v-e970bbc0><div class="aside" data-v-e970bbc0><div class="aside-curtain" data-v-e970bbc0></div><div class="aside-container" data-v-e970bbc0><div class="aside-content" data-v-e970bbc0><div class="VPDocAside" data-v-e970bbc0 data-v-0473afe5><!--[--><!--]--><!--[--><!--]--><div class="VPDocAsideOutline" role="navigation" data-v-0473afe5 data-v-b2f90363><div class="content" data-v-b2f90363><div class="outline-marker" data-v-b2f90363></div><div class="outline-title" role="heading" aria-level="2" data-v-b2f90363>目录</div><nav aria-labelledby="doc-outline-aria-label" data-v-b2f90363><span class="visually-hidden" id="doc-outline-aria-label" data-v-b2f90363> Table of Contents for current page </span><ul class="root" data-v-b2f90363 data-v-3d0f3048><!--[--><!--]--></ul></nav></div></div><!--[--><!--]--><div class="spacer" data-v-0473afe5></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-e970bbc0><div class="content-container" data-v-e970bbc0><!--[--><!--]--><!----><main class="main" data-v-e970bbc0><div style="position:relative;" class="vp-doc _tools-dev-maven" data-v-e970bbc0><div><h1 id="maven" tabindex="-1">Maven <a class="header-anchor" href="#maven" aria-label="Permalink to "Maven""></a></h1><h2 id="项目构建工具的前世今生" tabindex="-1">项目构建工具的前世今生 <a class="header-anchor" href="#项目构建工具的前世今生" aria-label="Permalink to "项目构建工具的前世今生""></a></h2><h3 id="ant" tabindex="-1"><strong>Ant</strong> <a class="header-anchor" href="#ant" aria-label="Permalink to "**Ant**""></a></h3><p>Ant是第一个所谓的“现代构建工具”,用于自动化构建过程。它是用Java实现的,主要用于Java项目。Ant的第一个公开发行版是在2000年,它很快成为Java项目最流行的构建工具,这要归功于它的平台独立性(如Java),设置门槛低,并提供可重复的构建。后来,它还获得了接受插件的能力。</p><h3 id="maven-1" tabindex="-1"><strong>Maven</strong> <a class="header-anchor" href="#maven-1" aria-label="Permalink to "**Maven**""></a></h3><p>Maven于2004年首次发布,旨在改进开发人员在使用Ant和其他构建工具时遇到的一些问题。Maven最大的成就被认为是引入了项目结构约定、依赖关系管理和一个中心工件库Maven central。</p><h3 id="gradle" tabindex="-1"><strong>Gradle</strong> <a class="header-anchor" href="#gradle" aria-label="Permalink to "**Gradle**""></a></h3><p>Gradle是三个构建工具中最年轻的一个,它的开发人员试图将Ant的能力和灵活性与Maven的依赖关系管理和约定结合起来,以创建漂亮而闪亮的构建工具。经过几年的开发,GradleV1.0于2012年发布,并迅速开始流行起来。它发展得非常快,已经被一些大企业采用——例如,Gradle被选为谷歌Android操作系统的构建工具。</p><p>一个有趣的观点是,在Gradle中,XML不再被使用。相反,开发人员拥有一种基于JVM语言Groovy的领域特定语言(DSL),Groovy的发明是为了让开发人员摆脱XML的冗长,编写更简单、更清晰的语句。这在用户中引发了一场争论,即标准的、易于理解的(但冗长的)XML样式比DSL好还是坏。</p><h2 id="maven介绍" tabindex="-1">Maven介绍 <a class="header-anchor" href="#maven介绍" aria-label="Permalink to "Maven介绍""></a></h2><h3 id="什么是maven" tabindex="-1">什么是Maven <a class="header-anchor" href="#什么是maven" aria-label="Permalink to "什么是Maven""></a></h3><p>Maven是项目进行模型抽象,充分运用的面向对象的思想,Maven可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具。Maven 除了以程序构建能力为特色之外,还提供高级项目管理工具。由于 Maven 的缺省构建规则有较高的可重用性,所以常常用两三行 Maven 构建脚本就可以构建简单的项目。</p><p>说白了: <strong>Maven是由Apache开发的一个工具</strong>。用来管理java项目(依赖(jar)管理, 项目构建, 分模块开发 ,管理项目的生命周期).</p><p><strong>官网</strong>:<a href="http://maven.apache.org/" target="_blank" rel="noreferrer">http://maven.apache.org/</a></p><blockquote><p>Maven是Apache软件基金会唯一维护的一款<strong>自动化构建工具</strong>,专注于服务Java平台的<strong>项目构建</strong>和<strong>依赖管理</strong>。</p></blockquote><p>Maven是一个强大的Java项目构建工具,基于POM(项目对象模型)文件,可用于项目构建、依赖模块管理和Javadoc生成等。</p><p>Maven 是一种<strong>声明式</strong>项目管理工具,通过在 POM 中配置 "who","what","where"等信息,即可满足编译、测试、打包、发布等项目构建需求。</p><h3 id="maven的作用" tabindex="-1">Maven的作用 <a class="header-anchor" href="#maven的作用" aria-label="Permalink to "Maven的作用""></a></h3><ul><li><p>依赖管理: maven对项目的第三方构件(jar包)进行统一管理。向工程中加入jar包不要手工从其它地方拷贝,通过maven定义jar包的坐标,自动从maven仓库中去下载到工程中。</p></li><li><p>项目构建: maven提供一套对项目生命周期管理的标准,开发人员、和测试人员统一使用maven进行项目构建。项目生命周期管理:编译、测试、打包、部署、运行。</p></li><li><p>maven对工程分模块构建,提高开发效率。 (后面Maven高级会涉及)</p></li></ul><h3 id="为什么用maven" tabindex="-1">为什么用Maven? <a class="header-anchor" href="#为什么用maven" aria-label="Permalink to "为什么用Maven?""></a></h3><h4 id="_1-jar包的规模" tabindex="-1">(1)jar包的规模 <a class="header-anchor" href="#_1-jar包的规模" aria-label="Permalink to "(1)jar包的规模""></a></h4><p>随着我们使用越来越多的框架,或者框架封装程度越来越高,项目中使用的jar包也越来越多。项目中,一个模块里面用到上百个jar包是非常正常的。</p><p>比如下面的例子,我们只用到 SpringBoot、SpringCloud 框架中的三个功能:</p><ul><li>Nacos 服务注册发现</li><li>Web 框架环境</li><li>图模板技术 Thymeleaf</li></ul><p>最终却导入了 106 个 jar 包:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;">org.springframework.security:spring-security-rsa:jar:1.0.9.RELEASE:compile com.netflix.ribbon: ribbon:jar:2.3.0:compile org.springframework.boot:spring-boot-starter-thymeleaf:jar:2.3.6.RELEASE:compile commons-configuration:commons-configuration:jar:1.8:compile org.apache.logging.log4j:log4j-api:jar:2.13.3:compile org.springframework:spring-beans:jar:5.2.11.RELEASE:compile org.springframework.cloud:spring-cloud-starter-netflix-ribbon:jar:2.2.6.RELEASE:compile org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.39:compile com.alibaba.cloud:spring-cloud-alibaba-commons:jar:2.2.6.RELEASE:compile org.bouncycastle:bcprov-jdk15on:jar:1.64:compile org.springframework.security:spring-security-crypto:jar:5.3.5.RELEASE:compile org.apache.httpcomponents:httpasyncclient:jar:4.1.4:compile com.google.j2objc:j2objc-annotations:jar:1.3:compile com.fasterxml.jackson.core:jackson-databind:jar:2.11.3:compile io.reactivex:rxjava:jar:1.3.8:compile ch.qos.logback:logback-classic:jar:1.2.3:compile org.springframework:spring-web:jar:5.2.11.RELEASE:compile io.reactivex:rxnetty-servo:jar:0.4.9:runtime org.springframework:spring-core:jar:5.2.11.RELEASE:compile io.github.openfeign.form:feign-form-spring:jar:3.8.0:compile io.github.openfeign.form:feign-form:jar:3.8.0:compile com.netflix.ribbon:ribbon-loadbalancer:jar:2.3.0:compile org.apache.httpcomponents:httpcore:jar:4.4.13:compile org.thymeleaf.extras:thymeleaf-extras-java8time:jar:3.0.4.RELEASE:compile org.slf4j:jul-to-slf4j:jar:1.7.30:compile com.itheima.demo:demo09-base-entity:jar:1.0-SNAPSHOT:compile org.yaml:snakeyaml:jar:1.26:compile org.springframework.boot:spring-boot-starter-logging:jar:2.3.6.RELEASE:compile io.reactivex:rxnetty-contexts:jar:0.4.9:runtime org.apache.httpcomponents:httpclient:jar:4.5.13:compile io.github.openfeign:feign-core:jar:10.10.1:compile org.springframework.boot:spring-boot-starter-aop:jar:2.3.6.RELEASE:compile org.hdrhistogram:HdrHistogram:jar:2.1.9:compile org.springframework:spring-context:jar:5.2.11.RELEASE:compile commons-lang:commons-lang:jar:2.6:compile io.prometheus:simpleclient:jar:0.5.0:compile ch.qos.logback:logback-core:jar:1.2.3:compile org.springframework:spring-webmvc:jar:5.2.11.RELEASE:compile com.sun.jersey:jersey-core:jar:1.19.1:runtime javax.ws.rs:jsr311-api:jar:1.1.1:runtime javax.inject:javax.inject:jar:1:runtime org.springframework.cloud:spring-cloud-openfeign-core:jar:2.2.6.RELEASE:compile com.netflix.ribbon:ribbon-core:jar:2.3.0:compile com.netflix.hystrix:hystrix-core:jar:1.5.18:compile com.netflix.ribbon:ribbon-transport:jar:2.3.0:runtime org.springframework.boot:spring-boot-starter-json:jar:2.3.6.RELEASE:compile org.springframework.cloud:spring-cloud-starter-openfeign:jar:2.2.6.RELEASE:compile com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.11.3:compile com.sun.jersey.contribs:jersey-apache-client4:jar:1.19.1:runtime io.github.openfeign:feign-hystrix:jar:10.10.1:compile io.github.openfeign:feign-slf4j:jar:10.10.1:compile com.alibaba.nacos:nacos-client:jar:1.4.2:compile org.apache.httpcomponents:httpcore-nio:jar:4.4.13:compile com.sun.jersey:jersey-client:jar:1.19.1:runtime org.springframework.cloud:spring-cloud-context:jar:2.2.6.RELEASE:compile org.glassfish:jakarta.el:jar:3.0.3:compile org.apache.logging.log4j:log4j-to-slf4j:jar:2.13.3:compile com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.11.3:compile org.springframework.cloud:spring-cloud-commons:jar:2.2.6.RELEASE:compile org.aspectj:aspectjweaver:jar:1.9.6:compile com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery:jar:2.2.6.RELEASE:compile com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile com.alibaba.spring:spring-context-support:jar:1.0.10:compile jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile org.bouncycastle:bcpkix-jdk15on:jar:1.64:compile com.netflix.netflix-commons:netflix-commons-util:jar:0.3.0:runtime com.fasterxml.jackson.core:jackson-annotations:jar:2.11.3:compile com.google.guava:guava:jar:29.0-jre:compile com.google.guava:failureaccess:jar:1.0.1:compile org.springframework.boot:spring-boot:jar:2.3.6.RELEASE:compile com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.11.3:compile com.itheima.demo:demo08-base-api:jar:1.0-SNAPSHOT:compile org.springframework.cloud:spring-cloud-starter-netflix-archaius:jar:2.2.6.RELEASE:compile org.springframework.boot:spring-boot-autoconfigure:jar:2.3.6.RELEASE:compile org.slf4j:slf4j-api:jar:1.7.30:compile commons-io:commons-io:jar:2.7:compile org.springframework.cloud:spring-cloud-starter:jar:2.2.6.RELEASE:compile org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.39:compile io.reactivex:rxnetty:jar:0.4.9:runtime com.fasterxml.jackson.core:jackson-core:jar:2.11.3:compile com.google.code.findbugs:jsr305:jar:3.0.2:compile com.netflix.archaius:archaius-core:jar:0.7.6:compile org.springframework.boot:spring-boot-starter-web:jar:2.3.6.RELEASE:compile commons-codec:commons-codec:jar:1.14:compile com.netflix.servo:servo-core:jar:0.12.21:runtime com.google.errorprone:error_prone_annotations:jar:2.3.4:compile org.attoparser:attoparser:jar:2.0.5.RELEASE:compile com.itheima.demo:demo10-base-util:jar:1.0-SNAPSHOT:compile org.checkerframework:checker-qual:jar:2.11.1:compile org.thymeleaf:thymeleaf-spring5:jar:3.0.11.RELEASE:compile commons-fileupload:commons-fileupload:jar:1.4:compile com.netflix.ribbon:ribbon-httpclient:jar:2.3.0:compile com.netflix.netflix-commons:netflix-statistics:jar:0.1.1:runtime org.unbescape:unbescape:jar:1.1.6.RELEASE:compile org.springframework:spring-jcl:jar:5.2.11.RELEASE:compile com.alibaba.nacos:nacos-common:jar:1.4.2:compile commons-collections:commons-collections:jar:3.2.2:runtime javax.persistence:persistence-api:jar:1.0:compile com.alibaba.nacos:nacos-api:jar:1.4.2:compile org.thymeleaf:thymeleaf:jar:3.0.11.RELEASE:compile org.springframework:spring-aop:jar:5.2.11.RELEASE:compile org.springframework.boot:spring-boot-starter:jar:2.3.6.RELEASE:compile org.springframework.boot:spring-boot-starter-tomcat:jar:2.3.6.RELEASE:compile org.springframework.cloud:spring-cloud-netflix-ribbon:jar:2.2.6.RELEASE:compile org.springframework:spring-expression:jar:5.2.11.RELEASE:compile org.springframework.cloud:spring-cloud-netflix-archaius:jar:2.2.6.RELEASE:compile</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;">org.springframework.security:spring-security-rsa:jar:1.0.9.RELEASE:compile com.netflix.ribbon: ribbon:jar:2.3.0:compile org.springframework.boot:spring-boot-starter-thymeleaf:jar:2.3.6.RELEASE:compile commons-configuration:commons-configuration:jar:1.8:compile org.apache.logging.log4j:log4j-api:jar:2.13.3:compile org.springframework:spring-beans:jar:5.2.11.RELEASE:compile org.springframework.cloud:spring-cloud-starter-netflix-ribbon:jar:2.2.6.RELEASE:compile org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.39:compile com.alibaba.cloud:spring-cloud-alibaba-commons:jar:2.2.6.RELEASE:compile org.bouncycastle:bcprov-jdk15on:jar:1.64:compile org.springframework.security:spring-security-crypto:jar:5.3.5.RELEASE:compile org.apache.httpcomponents:httpasyncclient:jar:4.1.4:compile com.google.j2objc:j2objc-annotations:jar:1.3:compile com.fasterxml.jackson.core:jackson-databind:jar:2.11.3:compile io.reactivex:rxjava:jar:1.3.8:compile ch.qos.logback:logback-classic:jar:1.2.3:compile org.springframework:spring-web:jar:5.2.11.RELEASE:compile io.reactivex:rxnetty-servo:jar:0.4.9:runtime org.springframework:spring-core:jar:5.2.11.RELEASE:compile io.github.openfeign.form:feign-form-spring:jar:3.8.0:compile io.github.openfeign.form:feign-form:jar:3.8.0:compile com.netflix.ribbon:ribbon-loadbalancer:jar:2.3.0:compile org.apache.httpcomponents:httpcore:jar:4.4.13:compile org.thymeleaf.extras:thymeleaf-extras-java8time:jar:3.0.4.RELEASE:compile org.slf4j:jul-to-slf4j:jar:1.7.30:compile com.itheima.demo:demo09-base-entity:jar:1.0-SNAPSHOT:compile org.yaml:snakeyaml:jar:1.26:compile org.springframework.boot:spring-boot-starter-logging:jar:2.3.6.RELEASE:compile io.reactivex:rxnetty-contexts:jar:0.4.9:runtime org.apache.httpcomponents:httpclient:jar:4.5.13:compile io.github.openfeign:feign-core:jar:10.10.1:compile org.springframework.boot:spring-boot-starter-aop:jar:2.3.6.RELEASE:compile org.hdrhistogram:HdrHistogram:jar:2.1.9:compile org.springframework:spring-context:jar:5.2.11.RELEASE:compile commons-lang:commons-lang:jar:2.6:compile io.prometheus:simpleclient:jar:0.5.0:compile ch.qos.logback:logback-core:jar:1.2.3:compile org.springframework:spring-webmvc:jar:5.2.11.RELEASE:compile com.sun.jersey:jersey-core:jar:1.19.1:runtime javax.ws.rs:jsr311-api:jar:1.1.1:runtime javax.inject:javax.inject:jar:1:runtime org.springframework.cloud:spring-cloud-openfeign-core:jar:2.2.6.RELEASE:compile com.netflix.ribbon:ribbon-core:jar:2.3.0:compile com.netflix.hystrix:hystrix-core:jar:1.5.18:compile com.netflix.ribbon:ribbon-transport:jar:2.3.0:runtime org.springframework.boot:spring-boot-starter-json:jar:2.3.6.RELEASE:compile org.springframework.cloud:spring-cloud-starter-openfeign:jar:2.2.6.RELEASE:compile com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.11.3:compile com.sun.jersey.contribs:jersey-apache-client4:jar:1.19.1:runtime io.github.openfeign:feign-hystrix:jar:10.10.1:compile io.github.openfeign:feign-slf4j:jar:10.10.1:compile com.alibaba.nacos:nacos-client:jar:1.4.2:compile org.apache.httpcomponents:httpcore-nio:jar:4.4.13:compile com.sun.jersey:jersey-client:jar:1.19.1:runtime org.springframework.cloud:spring-cloud-context:jar:2.2.6.RELEASE:compile org.glassfish:jakarta.el:jar:3.0.3:compile org.apache.logging.log4j:log4j-to-slf4j:jar:2.13.3:compile com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.11.3:compile org.springframework.cloud:spring-cloud-commons:jar:2.2.6.RELEASE:compile org.aspectj:aspectjweaver:jar:1.9.6:compile com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery:jar:2.2.6.RELEASE:compile com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile com.alibaba.spring:spring-context-support:jar:1.0.10:compile jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile org.bouncycastle:bcpkix-jdk15on:jar:1.64:compile com.netflix.netflix-commons:netflix-commons-util:jar:0.3.0:runtime com.fasterxml.jackson.core:jackson-annotations:jar:2.11.3:compile com.google.guava:guava:jar:29.0-jre:compile com.google.guava:failureaccess:jar:1.0.1:compile org.springframework.boot:spring-boot:jar:2.3.6.RELEASE:compile com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.11.3:compile com.itheima.demo:demo08-base-api:jar:1.0-SNAPSHOT:compile org.springframework.cloud:spring-cloud-starter-netflix-archaius:jar:2.2.6.RELEASE:compile org.springframework.boot:spring-boot-autoconfigure:jar:2.3.6.RELEASE:compile org.slf4j:slf4j-api:jar:1.7.30:compile commons-io:commons-io:jar:2.7:compile org.springframework.cloud:spring-cloud-starter:jar:2.2.6.RELEASE:compile org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.39:compile io.reactivex:rxnetty:jar:0.4.9:runtime com.fasterxml.jackson.core:jackson-core:jar:2.11.3:compile com.google.code.findbugs:jsr305:jar:3.0.2:compile com.netflix.archaius:archaius-core:jar:0.7.6:compile org.springframework.boot:spring-boot-starter-web:jar:2.3.6.RELEASE:compile commons-codec:commons-codec:jar:1.14:compile com.netflix.servo:servo-core:jar:0.12.21:runtime com.google.errorprone:error_prone_annotations:jar:2.3.4:compile org.attoparser:attoparser:jar:2.0.5.RELEASE:compile com.itheima.demo:demo10-base-util:jar:1.0-SNAPSHOT:compile org.checkerframework:checker-qual:jar:2.11.1:compile org.thymeleaf:thymeleaf-spring5:jar:3.0.11.RELEASE:compile commons-fileupload:commons-fileupload:jar:1.4:compile com.netflix.ribbon:ribbon-httpclient:jar:2.3.0:compile com.netflix.netflix-commons:netflix-statistics:jar:0.1.1:runtime org.unbescape:unbescape:jar:1.1.6.RELEASE:compile org.springframework:spring-jcl:jar:5.2.11.RELEASE:compile com.alibaba.nacos:nacos-common:jar:1.4.2:compile commons-collections:commons-collections:jar:3.2.2:runtime javax.persistence:persistence-api:jar:1.0:compile com.alibaba.nacos:nacos-api:jar:1.4.2:compile org.thymeleaf:thymeleaf:jar:3.0.11.RELEASE:compile org.springframework:spring-aop:jar:5.2.11.RELEASE:compile org.springframework.boot:spring-boot-starter:jar:2.3.6.RELEASE:compile org.springframework.boot:spring-boot-starter-tomcat:jar:2.3.6.RELEASE:compile org.springframework.cloud:spring-cloud-netflix-ribbon:jar:2.2.6.RELEASE:compile org.springframework:spring-expression:jar:5.2.11.RELEASE:compile org.springframework.cloud:spring-cloud-netflix-archaius:jar:2.2.6.RELEASE:compile</span></span></code></pre></div><p>而如果使用 Maven 来引入这些 jar 包只需要配置三个『<strong>依赖</strong>』:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><!-- Nacos 服务注册发现启动器 --></span></span>
<span class="line"><span style="color:#e1e4e8;"> <dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>com.alibaba.cloud</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> </dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"></span></span>
<span class="line"><span style="color:#e1e4e8;"> <!-- web启动器依赖 --></span></span>
<span class="line"><span style="color:#e1e4e8;"> <dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>spring-boot-starter-web</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> </dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"></span></span>
<span class="line"><span style="color:#e1e4e8;"> <!-- 视图模板技术 thymeleaf --></span></span>
<span class="line"><span style="color:#e1e4e8;"> <dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>spring-boot-starter-thymeleaf</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> </dependency></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><!-- Nacos 服务注册发现启动器 --></span></span>
<span class="line"><span style="color:#24292e;"> <dependency></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>com.alibaba.cloud</groupId></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> </dependency></span></span>
<span class="line"><span style="color:#24292e;"></span></span>
<span class="line"><span style="color:#24292e;"> <!-- web启动器依赖 --></span></span>
<span class="line"><span style="color:#24292e;"> <dependency></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>spring-boot-starter-web</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> </dependency></span></span>
<span class="line"><span style="color:#24292e;"></span></span>
<span class="line"><span style="color:#24292e;"> <!-- 视图模板技术 thymeleaf --></span></span>
<span class="line"><span style="color:#24292e;"> <dependency></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>spring-boot-starter-thymeleaf</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> </dependency></span></span></code></pre></div><h4 id="_2-jar包的来源" tabindex="-1">(2)jar包的来源 <a class="header-anchor" href="#_2-jar包的来源" aria-label="Permalink to "(2)jar包的来源""></a></h4><ul><li>这个jar包所属技术的官网。官网通常是英文界面,网站的结构又不尽相同,甚至找到下载链接还发现需要通过特殊的工具下载。</li><li>第三方网站提供下载。问题是不规范,在使用过程中会出现各种问题。 <ul><li>jar包的名称</li><li>jar包的版本</li><li>jar包内的具体细节</li></ul></li><li>而使用 Maven 后,依赖对应的 jar 包能够<strong>自动下载</strong>,方便、快捷又规范。</li></ul><h4 id="_3-jar包之间的依赖关系" tabindex="-1">(3)jar包之间的依赖关系 <a class="header-anchor" href="#_3-jar包之间的依赖关系" aria-label="Permalink to "(3)jar包之间的依赖关系""></a></h4><p>框架中使用的 jar 包,不仅数量庞大,而且彼此之间存在错综复杂的依赖关系。依赖关系的复杂程度,已经上升到了完全不能靠人力手动解决的程度。另外,jar 包之间有可能产生冲突。进一步增加了我们在 jar 包使用过程中的难度。</p><p>下面是前面例子中 jar 包之间的依赖关系:</p><p><img src="/images/image-20230917161342014.png" alt="image-20230917161342014"></p><p>而实际上 jar 包之间的依赖关系是普遍存在的,如果要由程序员手动梳理无疑会增加极高的学习成本,而这些工作又对实现业务功能毫无帮助。</p><p>而使用 Maven 则几乎不需要管理这些关系,极个别的地方调整一下即可,极大的减轻了我们的工作量。</p><h3 id="maven的好处" tabindex="-1">Maven的好处 <a class="header-anchor" href="#maven的好处" aria-label="Permalink to "Maven的好处""></a></h3><ul><li>使用普通方式构建项目</li></ul><p><img src="/images/image-20230917161334678.png" alt="image-20230917161334678"></p><ul><li><p>使用Maven构建项目</p><p><img src="/images/image-20230917161330837.png" alt="image-20230917161330837"></p></li></ul><h2 id="maven仓库和坐标-重点" tabindex="-1">Maven仓库和坐标(重点) <a class="header-anchor" href="#maven仓库和坐标-重点" aria-label="Permalink to "Maven仓库和坐标(重点)""></a></h2><h3 id="maven的仓库" tabindex="-1">Maven的仓库 <a class="header-anchor" href="#maven的仓库" aria-label="Permalink to "Maven的仓库""></a></h3><blockquote><p>Maven 仓库是项目中依赖的第三方库</p></blockquote><p>在 Maven 中,任何一个依赖、插件或者项目构建的输出,都可以称之为构件,Maven 仓库能帮助我们管理构件(主要是JAR),它就是放置所有JAR文件(WAR,ZIP,POM等等)的地方</p><table><thead><tr><th>仓库名称</th><th>作用</th></tr></thead><tbody><tr><td>本地仓库</td><td>相当于缓存,工程第一次会从远程仓库(互联网)去下载jar 包,将jar包存在本地仓库(在程序员的电脑上)。第二次不需要从远程仓库去下载。先从本地仓库找,如果找不到才会去远程仓库找。</td></tr><tr><td>中央仓库</td><td>仓库中jar由专业团队(maven团队)统一维护。中央仓库的地址:<a href="https://repo1.maven.org/maven2/" target="_blank" rel="noreferrer">https://repo1.maven.org/maven2/</a></td></tr><tr><td>远程仓库</td><td>在公司内部架设一台私服,其它公司架设一台仓库,对外公开。</td></tr></tbody></table><p>注意:除本地仓库以外的仓库都可以叫做远程仓库</p><p>当项目编译时,Maven首先从本地仓库中寻找项目所需的Jar包,若本地仓库没有,再到Maven的中央仓库下载所需Jar包,这 3 个仓库中,jar包的查找顺序如下:</p><p><img src="/images/image-20220411100417881.png" alt="image-20220411100417881"></p><h4 id="本地仓库" tabindex="-1">本地仓库 <a class="header-anchor" href="#本地仓库" aria-label="Permalink to "本地仓库""></a></h4><blockquote><p>Maven 的本地仓库,在安装 Maven 后并不会创建,它是在第一次执行 maven 命令的时候才被创建。默认位置:<code>当前用户名\.m2\repository。</code></p></blockquote><p>运行 Maven 的时候,Maven 所需要的任何构件都是直接从本地仓库获取的,如果本地仓库没有,它会首先尝试从远程仓库下载构件至本地仓库,然后再使用本地仓库的构件。</p><p>本地仓库默认位置在 <code>当前用户名\.m2\repository</code>,我们也可以修改本地仓库的位置,在 maven 安装目录下的 <code>conf/settings.xml</code>文件中可以修改,在该配置文件中可以看到 localRepository 节点被注释掉了,我们可以直接复制该节点,将值修改为本地路径即可</p><div class="language-xml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#6A737D;"><!-- localRepository</span></span>
<span class="line"><span style="color:#6A737D;"> | The path to the local repository maven will use to store artifacts.</span></span>
<span class="line"><span style="color:#6A737D;"> |</span></span>
<span class="line"><span style="color:#6A737D;"> | Default: ${user.home}/.m2/repository</span></span>
<span class="line"><span style="color:#6A737D;"> <localRepository>/path/to/local/repo</localRepository></span></span>
<span class="line"><span style="color:#6A737D;"> --></span></span>
<span class="line"><span style="color:#E1E4E8;"><</span><span style="color:#85E89D;">localRepository</span><span style="color:#E1E4E8;">>E:/develop/maven_repository</</span><span style="color:#85E89D;">localRepository</span><span style="color:#E1E4E8;">></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#6A737D;"><!-- localRepository</span></span>
<span class="line"><span style="color:#6A737D;"> | The path to the local repository maven will use to store artifacts.</span></span>
<span class="line"><span style="color:#6A737D;"> |</span></span>
<span class="line"><span style="color:#6A737D;"> | Default: ${user.home}/.m2/repository</span></span>
<span class="line"><span style="color:#6A737D;"> <localRepository>/path/to/local/repo</localRepository></span></span>
<span class="line"><span style="color:#6A737D;"> --></span></span>
<span class="line"><span style="color:#24292E;"><</span><span style="color:#22863A;">localRepository</span><span style="color:#24292E;">>E:/develop/maven_repository</</span><span style="color:#22863A;">localRepository</span><span style="color:#24292E;">></span></span></code></pre></div><p>当你运行 Maven 命令,Maven 会将下载依赖的文件放到你指定的路径中。</p><h4 id="中央仓库" tabindex="-1">中央仓库 <a class="header-anchor" href="#中央仓库" aria-label="Permalink to "中央仓库""></a></h4><blockquote><p>中央仓库属于远程仓库的一种,Maven 中央仓库是由 Maven 社区提供的仓库,其中包含了绝大多数流行的开源Java构件,以及源码、作者信息、SCM、信息、许可证信息等,一般来说,简单的Java项目依赖的包都可以在这里下载到</p></blockquote><p>中央仓库需要通过网络才能访问,低版本的 maven 中,比如 <code>maven-2.0.10</code>,可以在 <code>${M2_HOME}/lib/maven-2.0.10-uber.jar</code> 中找到 pom.xml 配置文件</p><p>但是在 3.xxx 版本及之后的版本,在 maven 安装目录下的<code>lib/maven-model-builder-${version}.jar</code>下,可以在 <code>\org\apache\maven\model\pom-4.0.0.xml</code>取到 <code>pom-4.0.0.xml</code> 配置文件,该配置文件是所有 Maven POM 的父 POM,所有Maven项目继承该配置</p><p><img src="/images/image-20220411101018514.png" alt="image-20220411101018514"></p><p>你可以在 pom-4.0.0.xml 配置文件中找到如下配置信息</p><div class="language-xml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#E1E4E8;"><</span><span style="color:#85E89D;">repositories</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">repository</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">>central</</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">name</span><span style="color:#E1E4E8;">>Central Repository</</span><span style="color:#85E89D;">name</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </span><span style="color:#6A737D;"><!-- 默认的中央仓库地址 --></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">>https://repo.maven.apache.org/maven2</</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">layout</span><span style="color:#E1E4E8;">>default</</span><span style="color:#85E89D;">layout</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">snapshots</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">enabled</span><span style="color:#E1E4E8;">>false</</span><span style="color:#85E89D;">enabled</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">snapshots</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">repository</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"></</span><span style="color:#85E89D;">repositories</span><span style="color:#E1E4E8;">></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292E;"><</span><span style="color:#22863A;">repositories</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">repository</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">id</span><span style="color:#24292E;">>central</</span><span style="color:#22863A;">id</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">name</span><span style="color:#24292E;">>Central Repository</</span><span style="color:#22863A;">name</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </span><span style="color:#6A737D;"><!-- 默认的中央仓库地址 --></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">url</span><span style="color:#24292E;">>https://repo.maven.apache.org/maven2</</span><span style="color:#22863A;">url</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">layout</span><span style="color:#24292E;">>default</</span><span style="color:#22863A;">layout</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">snapshots</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">enabled</span><span style="color:#24292E;">>false</</span><span style="color:#22863A;">enabled</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">snapshots</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">repository</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"></</span><span style="color:#22863A;">repositories</span><span style="color:#24292E;">></span></span></code></pre></div><p>可以看到,中央仓库的id为central,远程url地址为 <code>https://repo.maven.apache.org/maven2</code>,它关闭了snapshot版本构件下载的支持</p><blockquote><p>但是国外的远程库下载速度比较慢,甚至可能会出现无法访问的问题,此时我们可以配置国内的仓库,比如阿里云中央仓库等</p></blockquote><h3 id="maven的坐标" tabindex="-1">Maven的坐标 <a class="header-anchor" href="#maven的坐标" aria-label="Permalink to "Maven的坐标""></a></h3><p>Maven的一个核心的作用就是管理项目的依赖,引入我们所需的各种jar包等。为了能自动化的解析任何一个Java构件,Maven必须将这些Jar包或者其他资源进行唯一标识,这是管理项目的依赖的基础,也就是我们要说的坐标。包括我们自己开发的项目,也是要通过坐标进行唯一标识的,这样才能才其它项目中进行依赖引用。坐标的定义元素如下:</p><ul><li>groupId:项目组织唯一的标识符,实际对应JAVA的包的结构 (一般写公司的组织名称 eg:com.itheima,com.alibaba)</li><li>artifactId: 项目的名称</li><li>version:定义项目的当前版本</li></ul><p>例如:要引入druid,只需要在pom.xml配置文件中配置引入druid的坐标即可:</p><div class="language-xml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#E1E4E8;"><</span><span style="color:#85E89D;">dependecies</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </span><span style="color:#6A737D;"><!--druid连接池--></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">dependency</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">groupId</span><span style="color:#E1E4E8;">>com.alibaba</</span><span style="color:#85E89D;">groupId</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">artifactId</span><span style="color:#E1E4E8;">>druid</</span><span style="color:#85E89D;">artifactId</span><span style="color:#E1E4E8;">> </span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">version</span><span style="color:#E1E4E8;">>1.0.9</</span><span style="color:#85E89D;">version</span><span style="color:#E1E4E8;">> </span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">dependency</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">dependency</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">groupId</span><span style="color:#E1E4E8;">>mysql</</span><span style="color:#85E89D;">groupId</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">artifactId</span><span style="color:#E1E4E8;">>mysql-connector-java</</span><span style="color:#85E89D;">artifactId</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">version</span><span style="color:#E1E4E8;">>5.1.6</</span><span style="color:#85E89D;">version</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">dependency</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"></</span><span style="color:#85E89D;">dependecies</span><span style="color:#E1E4E8;">></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292E;"><</span><span style="color:#22863A;">dependecies</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </span><span style="color:#6A737D;"><!--druid连接池--></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">dependency</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">groupId</span><span style="color:#24292E;">>com.alibaba</</span><span style="color:#22863A;">groupId</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">artifactId</span><span style="color:#24292E;">>druid</</span><span style="color:#22863A;">artifactId</span><span style="color:#24292E;">> </span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">version</span><span style="color:#24292E;">>1.0.9</</span><span style="color:#22863A;">version</span><span style="color:#24292E;">> </span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">dependency</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">dependency</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">groupId</span><span style="color:#24292E;">>mysql</</span><span style="color:#22863A;">groupId</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">artifactId</span><span style="color:#24292E;">>mysql-connector-java</</span><span style="color:#22863A;">artifactId</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">version</span><span style="color:#24292E;">>5.1.6</</span><span style="color:#22863A;">version</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">dependency</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"></</span><span style="color:#22863A;">dependecies</span><span style="color:#24292E;">></span></span></code></pre></div><h3 id="小结" tabindex="-1">小结 <a class="header-anchor" href="#小结" aria-label="Permalink to "小结""></a></h3><ol><li>仓库(本地仓库,中央仓库,远程仓库(私服)) <ul><li>先从本地仓库找 <ul><li>如果有, 就直接获得使用</li><li>如果没有, 从中央仓库找, 自动的下载到本地仓库</li></ul></li></ul></li><li>通过坐标从仓库里面找到对应的jar使用</li></ol><div class="language-xml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#E1E4E8;"><</span><span style="color:#85E89D;">dependency</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">groupId</span><span style="color:#E1E4E8;">>com.alibaba</</span><span style="color:#85E89D;">groupId</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">artifactId</span><span style="color:#E1E4E8;">>druid</</span><span style="color:#85E89D;">artifactId</span><span style="color:#E1E4E8;">> </span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">version</span><span style="color:#E1E4E8;">>1.0.9</</span><span style="color:#85E89D;">version</span><span style="color:#E1E4E8;">> </span></span>
<span class="line"><span style="color:#E1E4E8;"></</span><span style="color:#85E89D;">dependency</span><span style="color:#E1E4E8;">></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292E;"><</span><span style="color:#22863A;">dependency</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">groupId</span><span style="color:#24292E;">>com.alibaba</</span><span style="color:#22863A;">groupId</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">artifactId</span><span style="color:#24292E;">>druid</</span><span style="color:#22863A;">artifactId</span><span style="color:#24292E;">> </span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">version</span><span style="color:#24292E;">>1.0.9</</span><span style="color:#22863A;">version</span><span style="color:#24292E;">> </span></span>
<span class="line"><span style="color:#24292E;"></</span><span style="color:#22863A;">dependency</span><span style="color:#24292E;">></span></span></code></pre></div><ol start="3"><li>maven坐标搜索网站的地址: <a href="https://mvnrepository.com/" target="_blank" rel="noreferrer">https://mvnrepository.com/</a></li><li>以后工作中maven坐标是直接拷贝</li></ol><h2 id="maven安装" tabindex="-1">Maven安装 <a class="header-anchor" href="#maven安装" aria-label="Permalink to "Maven安装""></a></h2><h3 id="下载maven" tabindex="-1">下载Maven <a class="header-anchor" href="#下载maven" aria-label="Permalink to "下载Maven""></a></h3><ul><li><a href="http://maven.apache.org/" target="_blank" rel="noreferrer">http://maven.apache.org/</a></li><li><a href="https://maven.apache.org/download.cgi" target="_blank" rel="noreferrer">Maven – Download Apache Maven</a></li></ul><p><img src="/images/image-20220629114326612.png" alt="image-20220629114326612"></p><p><img src="/images/image-20220629114414630.png" alt="image-20220629114414630"></p><h3 id="安装maven" tabindex="-1">安装Maven <a class="header-anchor" href="#安装maven" aria-label="Permalink to "安装Maven""></a></h3><p>将Maven压缩包解压,即安装完毕</p><p><img src="/images/image-20230917163659493.png" alt="image-20230917163659493"></p><h3 id="maven目录介绍" tabindex="-1">Maven目录介绍 <a class="header-anchor" href="#maven目录介绍" aria-label="Permalink to "Maven目录介绍""></a></h3><p><img src="/images/image-20230917163707054.png" alt="image-20230917163707054"></p><h3 id="配置环境变量" tabindex="-1">配置环境变量 <a class="header-anchor" href="#配置环境变量" aria-label="Permalink to "配置环境变量""></a></h3><p>配置JDK环境</p><blockquote><p>在环境变量中增加<code>MAVEN_HOME</code></p></blockquote><ol><li>先在系统变量当中添加一个环境变量 MAVEN_HOME,变量值为 maven 的安装目录的根目录,比如:<code>D:\dev\apache-maven-3.6.3</code></li></ol><p><img src="/images/image-20230917163737091.png" alt="image-20230917163737091"></p><ol start="2"><li>然后找到系统变量 Path,给该变量的值后面添加:<code>;%MAVEN_HOME%\bin</code> 即可</li></ol><p><img src="/images/image-20230917163743744.png" alt="image-20230917163743744"></p><ol start="3"><li>验证</li></ol><blockquote><p>检验 maven 安装是否成功,直接在命令窗口输入 mvn -v ,如果有输出 maven 的版本说明安装成功:</p></blockquote><p><img src="/images/image-20230917163748916.png" alt="image-20230917163748916"></p><h3 id="配置本地仓库" tabindex="-1">配置本地仓库 <a class="header-anchor" href="#配置本地仓库" aria-label="Permalink to "配置本地仓库""></a></h3><h4 id="将软件文件夹中的repository解压" tabindex="-1">将软件文件夹中的repository解压 <a class="header-anchor" href="#将软件文件夹中的repository解压" aria-label="Permalink to "将软件文件夹中的repository解压""></a></h4><p><img src="/images/image-20230917163759949.png" alt="image-20230917163759949"></p><h4 id="配置本地仓库-1" tabindex="-1">配置本地仓库 <a class="header-anchor" href="#配置本地仓库-1" aria-label="Permalink to "配置本地仓库""></a></h4><p>在maven的安装目录中conf/ settings.xml文件,在这里配置本地仓库</p><p><img src="/images/image-20230917163806073.png" alt="image-20230917163806073"></p><ul><li>示例代码</li></ul><div class="language-xml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#E1E4E8;"><</span><span style="color:#85E89D;">settings</span><span style="color:#E1E4E8;"> </span><span style="color:#B392F0;">xmlns</span><span style="color:#E1E4E8;">=</span><span style="color:#9ECBFF;">"http://maven.apache.org/SETTINGS/1.0.0"</span></span>
<span class="line"><span style="color:#E1E4E8;"> </span><span style="color:#B392F0;">xmlns:xsi</span><span style="color:#E1E4E8;">=</span><span style="color:#9ECBFF;">"http://www.w3.org/2001/XMLSchema-instance"</span></span>
<span class="line"><span style="color:#E1E4E8;"> </span><span style="color:#B392F0;">xsi:schemaLocation</span><span style="color:#E1E4E8;">=</span><span style="color:#9ECBFF;">"http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </span><span style="color:#6A737D;"><!-- localRepository</span></span>
<span class="line"><span style="color:#6A737D;"> | The path to the local repository maven will use to store artifacts.</span></span>
<span class="line"><span style="color:#6A737D;"> |</span></span>
<span class="line"><span style="color:#6A737D;"> | Default: ${user.home}/.m2/repository</span></span>
<span class="line"><span style="color:#6A737D;"> <localRepository>/path/to/local/repo</localRepository></span></span>
<span class="line"><span style="color:#6A737D;"> --></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">localRepository</span><span style="color:#E1E4E8;">>E:/source/04_Maven/repository_pinyougou</</span><span style="color:#85E89D;">localRepository</span><span style="color:#E1E4E8;">></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292E;"><</span><span style="color:#22863A;">settings</span><span style="color:#24292E;"> </span><span style="color:#6F42C1;">xmlns</span><span style="color:#24292E;">=</span><span style="color:#032F62;">"http://maven.apache.org/SETTINGS/1.0.0"</span></span>
<span class="line"><span style="color:#24292E;"> </span><span style="color:#6F42C1;">xmlns:xsi</span><span style="color:#24292E;">=</span><span style="color:#032F62;">"http://www.w3.org/2001/XMLSchema-instance"</span></span>
<span class="line"><span style="color:#24292E;"> </span><span style="color:#6F42C1;">xsi:schemaLocation</span><span style="color:#24292E;">=</span><span style="color:#032F62;">"http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </span><span style="color:#6A737D;"><!-- localRepository</span></span>
<span class="line"><span style="color:#6A737D;"> | The path to the local repository maven will use to store artifacts.</span></span>
<span class="line"><span style="color:#6A737D;"> |</span></span>
<span class="line"><span style="color:#6A737D;"> | Default: ${user.home}/.m2/repository</span></span>
<span class="line"><span style="color:#6A737D;"> <localRepository>/path/to/local/repo</localRepository></span></span>
<span class="line"><span style="color:#6A737D;"> --></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">localRepository</span><span style="color:#24292E;">>E:/source/04_Maven/repository_pinyougou</</span><span style="color:#22863A;">localRepository</span><span style="color:#24292E;">></span></span></code></pre></div><h3 id="测试maven安装成功" tabindex="-1">测试Maven安装成功 <a class="header-anchor" href="#测试maven安装成功" aria-label="Permalink to "测试Maven安装成功""></a></h3><p>打开cmd本地控制台,输入mvn -version</p><p><img src="/images/image-20230917165008699.png" alt="image-20230917165008699"></p><h3 id="小结-1" tabindex="-1">小结 <a class="header-anchor" href="#小结-1" aria-label="Permalink to "小结""></a></h3><ol><li>注意事项 <ul><li><code>Maven安装包</code> 和<code>仓库</code> 都需要解压到一个==没有中文和空格==的目录下(建议解压到不同的目录)</li><li>配置 <ul><li>MAVEN_HOME 配置到Maven的解压目录</li><li>Path 配置到bin目录</li></ul></li><li>在<code>apache-maven-3.3.9\conf\settings.xml</code>配置本地仓库</li></ul></li></ol><h3 id="项目中配置镜像仓库" tabindex="-1">项目中配置镜像仓库 <a class="header-anchor" href="#项目中配置镜像仓库" aria-label="Permalink to "项目中配置镜像仓库""></a></h3><blockquote><p>我们是可以在自己的项目中配置镜像仓库的</p></blockquote><p>配置我们自己的远程仓库有很多好处,比如你有一个局域网的远程仓库,使用该仓库能大大提高下载速度,继而提高构建速度,也有可能你依赖的一个 jar 在 central 中找不到,它只存在于某个特定的公共仓库,这样你也不得不添加那个远程仓库的配置。</p><blockquote><p>我们可以在项目的 pom.xml 文件中配置远程仓库。比如下面配置远程仓库指向阿里云仓库</p></blockquote><div class="language-xml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#E1E4E8;"><?</span><span style="color:#85E89D;">xml</span><span style="color:#B392F0;"> version</span><span style="color:#E1E4E8;">=</span><span style="color:#9ECBFF;">"1.0"</span><span style="color:#B392F0;"> encoding</span><span style="color:#E1E4E8;">=</span><span style="color:#9ECBFF;">"UTF-8"</span><span style="color:#E1E4E8;">?></span></span>
<span class="line"><span style="color:#E1E4E8;"><</span><span style="color:#85E89D;">project</span><span style="color:#E1E4E8;"> </span><span style="color:#B392F0;">xmlns</span><span style="color:#E1E4E8;">=</span><span style="color:#9ECBFF;">"http://maven.apache.org/POM/4.0.0"</span></span>
<span class="line"><span style="color:#E1E4E8;"> </span><span style="color:#B392F0;">xmlns:xsi</span><span style="color:#E1E4E8;">=</span><span style="color:#9ECBFF;">"http://www.w3.org/2001/XMLSchema-instance"</span></span>
<span class="line"><span style="color:#E1E4E8;"> </span><span style="color:#B392F0;">xsi:schemaLocation</span><span style="color:#E1E4E8;">=</span><span style="color:#9ECBFF;">"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">modelVersion</span><span style="color:#E1E4E8;">>4.0.0</</span><span style="color:#85E89D;">modelVersion</span><span style="color:#E1E4E8;">></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">groupId</span><span style="color:#E1E4E8;">>org.heima</</span><span style="color:#85E89D;">groupId</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">artifactId</span><span style="color:#E1E4E8;">>maven_project</</span><span style="color:#85E89D;">artifactId</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">version</span><span style="color:#E1E4E8;">>1.0-SNAPSHOT</</span><span style="color:#85E89D;">version</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">repositories</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">repository</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">>maven-ali</</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">>http://maven.aliyun.com/nexus/content/repositories/central</</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">releases</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">enabled</span><span style="color:#E1E4E8;">>true</</span><span style="color:#85E89D;">enabled</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">releases</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">snapshots</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">enabled</span><span style="color:#E1E4E8;">>true</</span><span style="color:#85E89D;">enabled</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">updatePolicy</span><span style="color:#E1E4E8;">>always</</span><span style="color:#85E89D;">updatePolicy</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">checksumPolicy</span><span style="color:#E1E4E8;">>fail</</span><span style="color:#85E89D;">checksumPolicy</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">snapshots</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">repository</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">repositories</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"></</span><span style="color:#85E89D;">project</span><span style="color:#E1E4E8;">></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292E;"><?</span><span style="color:#22863A;">xml</span><span style="color:#6F42C1;"> version</span><span style="color:#24292E;">=</span><span style="color:#032F62;">"1.0"</span><span style="color:#6F42C1;"> encoding</span><span style="color:#24292E;">=</span><span style="color:#032F62;">"UTF-8"</span><span style="color:#24292E;">?></span></span>
<span class="line"><span style="color:#24292E;"><</span><span style="color:#22863A;">project</span><span style="color:#24292E;"> </span><span style="color:#6F42C1;">xmlns</span><span style="color:#24292E;">=</span><span style="color:#032F62;">"http://maven.apache.org/POM/4.0.0"</span></span>
<span class="line"><span style="color:#24292E;"> </span><span style="color:#6F42C1;">xmlns:xsi</span><span style="color:#24292E;">=</span><span style="color:#032F62;">"http://www.w3.org/2001/XMLSchema-instance"</span></span>
<span class="line"><span style="color:#24292E;"> </span><span style="color:#6F42C1;">xsi:schemaLocation</span><span style="color:#24292E;">=</span><span style="color:#032F62;">"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">modelVersion</span><span style="color:#24292E;">>4.0.0</</span><span style="color:#22863A;">modelVersion</span><span style="color:#24292E;">></span></span>
<span class="line"></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">groupId</span><span style="color:#24292E;">>org.heima</</span><span style="color:#22863A;">groupId</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">artifactId</span><span style="color:#24292E;">>maven_project</</span><span style="color:#22863A;">artifactId</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">version</span><span style="color:#24292E;">>1.0-SNAPSHOT</</span><span style="color:#22863A;">version</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">repositories</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">repository</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">id</span><span style="color:#24292E;">>maven-ali</</span><span style="color:#22863A;">id</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">url</span><span style="color:#24292E;">>http://maven.aliyun.com/nexus/content/repositories/central</</span><span style="color:#22863A;">url</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">releases</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">enabled</span><span style="color:#24292E;">>true</</span><span style="color:#22863A;">enabled</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">releases</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">snapshots</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">enabled</span><span style="color:#24292E;">>true</</span><span style="color:#22863A;">enabled</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">updatePolicy</span><span style="color:#24292E;">>always</</span><span style="color:#22863A;">updatePolicy</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">checksumPolicy</span><span style="color:#24292E;">>fail</</span><span style="color:#22863A;">checksumPolicy</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">snapshots</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">repository</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">repositories</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"></</span><span style="color:#22863A;">project</span><span style="color:#24292E;">></span></span></code></pre></div><p><code><repositories></code>下面可以添加多个<code><repository></code>,每个<code><repository></code>都有它唯一的ID,一个描述性的name,以及最重要的远程仓库的url。</p><p><code><releases><enabled></code>true<code></enabled></releases></code>告诉Maven可以从这个仓库下载 releases 版本的构件,而<code><snapshots><enabled>false</enabled></snapshots></code> 告诉Maven不要从这个仓库下载 snapshot 版本的构件,禁止从公共仓库下载snapshot构件是推荐的做法,因为这些构件不稳定,且不受你控制,你应该避免使用,当然,如果你想使用局域网内组织内部的仓库,你可以激活snapshot的支持。</p><h3 id="settings-xml配置镜像仓库" tabindex="-1">settings.xml配置镜像仓库 <a class="header-anchor" href="#settings-xml配置镜像仓库" aria-label="Permalink to "settings.xml配置镜像仓库""></a></h3><blockquote><p>在项目的 pom.xml 文件中可以配置中央仓库,但是这样每个项目都需要配置一遍,需要重复工作</p></blockquote><p>我们可以直接在 maven 安装目录下的 conf/settings.xml 文件中配置中央仓库。</p><blockquote><p>找到 mirrors 标签,添加如下配置</p></blockquote><div class="language-xml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#E1E4E8;"><</span><span style="color:#85E89D;">mirrors</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </span><span style="color:#6A737D;"><!-- mirror</span></span>
<span class="line"><span style="color:#6A737D;"> | Specifies a repository mirror site to use instead of a given repository. The repository that</span></span>
<span class="line"><span style="color:#6A737D;"> | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used</span></span>
<span class="line"><span style="color:#6A737D;"> | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.</span></span>
<span class="line"><span style="color:#6A737D;"> |</span></span>
<span class="line"><span style="color:#6A737D;"> <mirror></span></span>
<span class="line"><span style="color:#6A737D;"> <id>mirrorId</id></span></span>
<span class="line"><span style="color:#6A737D;"> <mirrorOf>repositoryId</mirrorOf></span></span>
<span class="line"><span style="color:#6A737D;"> <name>Human Readable Name for this Mirror.</name></span></span>
<span class="line"><span style="color:#6A737D;"> <url>http://my.repository.com/repo/path</url></span></span>
<span class="line"><span style="color:#6A737D;"> </mirror></span></span>
<span class="line"><span style="color:#6A737D;"> --></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">mirror</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">>alimaven</</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">name</span><span style="color:#E1E4E8;">>aliyun maven</</span><span style="color:#85E89D;">name</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">>http://maven.aliyun.com/nexus/content/groups/public/</</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">mirrorOf</span><span style="color:#E1E4E8;">>central</</span><span style="color:#85E89D;">mirrorOf</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">mirror</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"></</span><span style="color:#85E89D;">mirrors</span><span style="color:#E1E4E8;">></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292E;"><</span><span style="color:#22863A;">mirrors</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </span><span style="color:#6A737D;"><!-- mirror</span></span>
<span class="line"><span style="color:#6A737D;"> | Specifies a repository mirror site to use instead of a given repository. The repository that</span></span>
<span class="line"><span style="color:#6A737D;"> | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used</span></span>
<span class="line"><span style="color:#6A737D;"> | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.</span></span>
<span class="line"><span style="color:#6A737D;"> |</span></span>
<span class="line"><span style="color:#6A737D;"> <mirror></span></span>
<span class="line"><span style="color:#6A737D;"> <id>mirrorId</id></span></span>
<span class="line"><span style="color:#6A737D;"> <mirrorOf>repositoryId</mirrorOf></span></span>
<span class="line"><span style="color:#6A737D;"> <name>Human Readable Name for this Mirror.</name></span></span>
<span class="line"><span style="color:#6A737D;"> <url>http://my.repository.com/repo/path</url></span></span>
<span class="line"><span style="color:#6A737D;"> </mirror></span></span>
<span class="line"><span style="color:#6A737D;"> --></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">mirror</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">id</span><span style="color:#24292E;">>alimaven</</span><span style="color:#22863A;">id</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">name</span><span style="color:#24292E;">>aliyun maven</</span><span style="color:#22863A;">name</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">url</span><span style="color:#24292E;">>http://maven.aliyun.com/nexus/content/groups/public/</</span><span style="color:#22863A;">url</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">mirrorOf</span><span style="color:#24292E;">>central</</span><span style="color:#22863A;">mirrorOf</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">mirror</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"></</span><span style="color:#22863A;">mirrors</span><span style="color:#24292E;">></span></span></code></pre></div><blockquote><p>可以看到 <code><mirrorOf></code> 的值是 central,意思就是用以上镜像替代 Maven 自带的中央仓库</p></blockquote><h2 id="idea集成maven-很重要" tabindex="-1">IDEA集成Maven(很重要) <a class="header-anchor" href="#idea集成maven-很重要" aria-label="Permalink to "IDEA集成Maven(很重要)""></a></h2><h3 id="maven在idea中配置" tabindex="-1">maven在idea中配置 <a class="header-anchor" href="#maven在idea中配置" aria-label="Permalink to "maven在idea中配置""></a></h3><ul><li>配置Maven</li></ul><p><img src="/images/image-20230917165131230.png" alt="image-20230917165131230"></p><p>配置默认Maven环境 目的: 为了下次创建的时候 不需要再选择Maven了, 使用的就是这个默认环境的</p><ul><li>配置参数(解决创建慢的问题) -DarchetypeCatalog=internal</li></ul><p><img src="/images/image-20230917165137881.png" alt="image-20230917165137881"></p><ul><li>然后新创建project,一定不要使用原来的project,要求各位第一次使用maven创建项目的时候,一定要联网</li></ul><h3 id="maven工程目录结构" tabindex="-1">maven工程目录结构 <a class="header-anchor" href="#maven工程目录结构" aria-label="Permalink to "maven工程目录结构""></a></h3><blockquote><p>Maven 提倡使用一个共同的标准目录结构,Maven 使用约定优于配置的原则,大家尽可能的遵守这样的目录结构,一个使用Maven管理的普通的Java项目,它的目录结构默认如下:</p></blockquote><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;">MavenProject</span></span>
<span class="line"><span style="color:#e1e4e8;"> |-- pom.xml maven项目的配置文件。对项目中的所有jar包依赖进行统一管理</span></span>
<span class="line"><span style="color:#e1e4e8;"> |-- src</span></span>
<span class="line"><span style="color:#e1e4e8;"> |-- main</span></span>
<span class="line"><span style="color:#e1e4e8;"> | -- java 存放项目源代码</span></span>
<span class="line"><span style="color:#e1e4e8;"> | -- resources(可省略) 存放项目配置文件 .xml等 </span></span>
<span class="line"><span style="color:#e1e4e8;"> |-- test(可省略)</span></span>
<span class="line"><span style="color:#e1e4e8;"> | -- java 存放单元测试源代码</span></span>
<span class="line"><span style="color:#e1e4e8;"> | -- resources 存放单元测试资源文件 .xml等</span></span>
<span class="line"><span style="color:#e1e4e8;"> |-- target(由maven生成) 存放所有编译、打包生成的文件</span></span>
<span class="line"><span style="color:#e1e4e8;"> |-- classes 存放项目源代码编译输出的字节码文件</span></span>
<span class="line"><span style="color:#e1e4e8;"> |-- test-classes 存放测试代码编译输出的字节码文件</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;">MavenProject</span></span>
<span class="line"><span style="color:#24292e;"> |-- pom.xml maven项目的配置文件。对项目中的所有jar包依赖进行统一管理</span></span>
<span class="line"><span style="color:#24292e;"> |-- src</span></span>
<span class="line"><span style="color:#24292e;"> |-- main</span></span>
<span class="line"><span style="color:#24292e;"> | -- java 存放项目源代码</span></span>
<span class="line"><span style="color:#24292e;"> | -- resources(可省略) 存放项目配置文件 .xml等 </span></span>
<span class="line"><span style="color:#24292e;"> |-- test(可省略)</span></span>
<span class="line"><span style="color:#24292e;"> | -- java 存放单元测试源代码</span></span>
<span class="line"><span style="color:#24292e;"> | -- resources 存放单元测试资源文件 .xml等</span></span>
<span class="line"><span style="color:#24292e;"> |-- target(由maven生成) 存放所有编译、打包生成的文件</span></span>
<span class="line"><span style="color:#24292e;"> |-- classes 存放项目源代码编译输出的字节码文件</span></span>
<span class="line"><span style="color:#24292e;"> |-- test-classes 存放测试代码编译输出的字节码文件</span></span></code></pre></div><pre><code> 默认情况下,项目在编译过后,会将 `src/main/java`编译过后的字节码文件和 `src/main/resource` 中的文件放在`target/classes`目录下。
但是,`src/main/java` 目录下的非包且非java的文件在编译过后并不会自动被拷贝在 `target/classes` 目录下,而是会丢失。
如果我们想要将 `src/main/java` 目录下的非包且非java的文件也一并拷贝在`target/classes` 目录下,则需要在 pom.xml 文件的 build 标签下进行配置。
</code></pre><h2 id="idea创建maven工程" tabindex="-1">IDEA创建Maven工程 <a class="header-anchor" href="#idea创建maven工程" aria-label="Permalink to "IDEA创建Maven工程""></a></h2><h3 id="创建javase工程" tabindex="-1">创建javase工程 <a class="header-anchor" href="#创建javase工程" aria-label="Permalink to "创建javase工程""></a></h3><h4 id="创建java工程" tabindex="-1">创建java工程 <a class="header-anchor" href="#创建java工程" aria-label="Permalink to "创建java工程""></a></h4><p><img src="/images/image-20230917165150888.png" alt="image-20230917165150888"></p><p><img src="/images/image-20230917165155380.png" alt="image-20230917165155380"></p><p><img src="/images/image-20230917165205360.png" alt="image-20230917165205360"></p><p><img src="/images/image-20230917165209507.png" alt="image-20230917165209507"></p><h4 id="java工程目录结构" tabindex="-1">java工程目录结构 <a class="header-anchor" href="#java工程目录结构" aria-label="Permalink to "java工程目录结构""></a></h4><ul><li>需要main/java文件夹变成 源码的目录(存放java源码)</li></ul><p><img src="/images/image-20230917165224205.png" alt="image-20230917165224205"></p><ul><li>需要test/java文件夹变成 测试源码的目录(存放单元测试)</li></ul><p><img src="/images/image-20230917165230097.png" alt="image-20230917165230097"></p><ul><li><p>创建resources目录, 变成资源的目录</p><p><img src="/images/image-20230917165234264.png" alt="image-20230917165234264"></p></li><li><p>整体结构</p><p><img src="/images/image-20230917165239875.png" alt="image-20230917165239875"></p></li></ul><h4 id="编写hello-world" tabindex="-1">编写Hello World! <a class="header-anchor" href="#编写hello-world" aria-label="Permalink to "编写Hello World!""></a></h4><p><img src="/images/image-20230917165246673.png" alt="image-20230917165246673"></p><p><img src="/images/image-20230917165251072.png" alt="image-20230917165251072"></p><h4 id="小结-2" tabindex="-1">小结 <a class="header-anchor" href="#小结-2" aria-label="Permalink to "小结""></a></h4><ol><li>JavaSe工程的骨架</li></ol><p><img src="/images/image-20230917165258729.png" alt="image-20230917165258729"></p><ol start="2"><li>项目的结构</li></ol><p><img src="/images/image-20230917165302519.png" alt="image-20230917165302519"></p><h3 id="创建javaweb工程" tabindex="-1">创建javaweb工程 <a class="header-anchor" href="#创建javaweb工程" aria-label="Permalink to "创建javaweb工程""></a></h3><h4 id="创建javaweb工程-1" tabindex="-1">创建javaweb工程 <a class="header-anchor" href="#创建javaweb工程-1" aria-label="Permalink to "创建javaweb工程""></a></h4><ul><li>创建javaweb工程与创建javase工程类似,但在选择Maven骨架时,选择maven-archetype-webapp即可:</li></ul><p><img src="/images/image-20230917165328243.png" alt="image-20230917165328243"></p><ul><li>创建好的javaweb工程如下:</li></ul><p><img src="/images/image-20230917165343821.png" alt="image-20230917165343821"></p><ul><li>所以,要手动创建一个java目录用于编写java代码:</li></ul><p><img src="/images/image-20230917165348494.png" alt="image-20230917165348494"></p><ul><li>还要将java目录添加为Source Root:</li></ul><p><img src="/images/image-20230917165354547.png" alt="image-20230917165354547"></p><h4 id="发布javaweb工程" tabindex="-1">发布javaweb工程 <a class="header-anchor" href="#发布javaweb工程" aria-label="Permalink to "发布javaweb工程""></a></h4><p><img src="/images/image-20230917165400107.png" alt="image-20230917165400107"></p><h4 id="浏览器访问效果" tabindex="-1">浏览器访问效果 <a class="header-anchor" href="#浏览器访问效果" aria-label="Permalink to "浏览器访问效果""></a></h4><p><img src="/images/image-20230917165404996.png" alt="image-20230917165404996"></p><h4 id="target目录" tabindex="-1">target目录 <a class="header-anchor" href="#target目录" aria-label="Permalink to "target目录""></a></h4><p><img src="/images/image-20220708033039215.png" alt="image-20220708033039215"></p><h4 id="小结-3" tabindex="-1">小结 <a class="header-anchor" href="#小结-3" aria-label="Permalink to "小结""></a></h4><ol><li>选择骨架选择webapp</li></ol><p><img src="/images/image-20191224105135578.png" alt="image-20191224105135578"></p><ol start="2"><li>pom.xml</li></ol><p><img src="/images/image-20191224105159688.png" alt="image-20191224105159688"></p><ol start="3"><li>web工程结构</li></ol><p><img src="/images/image-20191224105359670.png" alt="image-20191224105359670"></p><p><img src="/images/image-20220708032800465.png" alt="image-20220708032800465"></p><h3 id="不使用骨架创建工程" tabindex="-1">不使用骨架创建工程 <a class="header-anchor" href="#不使用骨架创建工程" aria-label="Permalink to "不使用骨架创建工程""></a></h3><h4 id="不使用骨架创建javase项目" tabindex="-1">不使用骨架创建javase项目 <a class="header-anchor" href="#不使用骨架创建javase项目" aria-label="Permalink to "不使用骨架创建javase项目""></a></h4><ul><li>第一步</li></ul><p><img src="/images/image-20230917165428212.png" alt="image-20230917165428212"></p><ul><li>第二步</li></ul><p><img src="/images/image-20230917165433082.png" alt="image-20230917165433082"></p><ul><li>第三步</li></ul><p><img src="/images/image-20230917165437380.png" alt="image-20230917165437380"></p><ul><li>第四步</li></ul><p><img src="/images/image-20230917165442221.png" alt="image-20230917165442221"></p><h4 id="不使用骨架创建javaweb项目" tabindex="-1">不使用骨架创建javaweb项目 <a class="header-anchor" href="#不使用骨架创建javaweb项目" aria-label="Permalink to "不使用骨架创建javaweb项目""></a></h4><ul><li>安装一个插件(JBLJavaToWeb)</li></ul><ul><li>第一步</li></ul><p><img src="/images/image-20230917165447201.png" alt="image-20230917165447201"></p><ul><li>第二步</li></ul><p><img src="/images/image-20230917170944047.png" alt="image-20230917170944047"></p><ul><li>第三步</li></ul><p><img src="/images/image-20230917170951224.png" alt="image-20230917170951224"></p><ul><li>第四步</li></ul><p><img src="/images/image-20230917170955706.png" alt="image-20230917170955706"></p><h4 id="小结-4" tabindex="-1">小结 <a class="header-anchor" href="#小结-4" aria-label="Permalink to "小结""></a></h4><p>我们可以使用JBLJavaToWeb插件,轻松地将没有使用骨架创建的java项目转换成javaweb项目</p><p><img src="/images/image-20220708032917810.png" alt="image-20220708032917810"></p><h2 id="maven常用命令" tabindex="-1">Maven常用命令 <a class="header-anchor" href="#maven常用命令" aria-label="Permalink to "Maven常用命令""></a></h2><p>Maven的常用命令管理项目的生命周期</p><h3 id="clean命令" tabindex="-1">clean命令 <a class="header-anchor" href="#clean命令" aria-label="Permalink to "clean命令""></a></h3><p><strong>清除编译产生的target文件夹内容</strong>,可以配合相应命令一起使用,如mvn clean package, mvn clean test</p><p><img src="/images/image-20230917171013024.png" alt="image-20230917171013024"></p><p><img src="/images/image-20230917171006970.png" alt="image-20230917171006970"></p><h3 id="compile命令" tabindex="-1">compile命令 <a class="header-anchor" href="#compile命令" aria-label="Permalink to "compile命令""></a></h3><p>该命令可以对src/main/java目录的下的代码进行编译</p><p><img src="/images/image-20230917171019732.png" alt="image-20230917171019732"></p><p><img src="/images/image-20230917171024179.png" alt="image-20230917171024179"></p><h3 id="test命令" tabindex="-1">test命令 <a class="header-anchor" href="#test命令" aria-label="Permalink to "test命令""></a></h3><p><strong>测试命令,先将src/main/java以及src/test/java中的类都进行编译,然后再执行src/test/java/下所有junit的测试用例</strong></p><p><img src="/images/image-20230917171031126.png" alt="image-20230917171031126"></p><ul><li>在src/test/java下创建测试类DemoTest</li></ul><p><img src="/images/image-20230917171034939.png" alt="image-20230917171034939"></p><ul><li>执行test命令测试</li></ul><p><img src="/images/image-20230917171215741.png" alt="image-20230917171215741"></p><ul><li>控制台显示测试结果</li></ul><p><img src="/images/image-20230917171220781.png" alt="image-20230917171220781"></p><h3 id="package命令" tabindex="-1">package命令 <a class="header-anchor" href="#package命令" aria-label="Permalink to "package命令""></a></h3><p>mvn package,打包项目</p><p>先编译,再执行测试,然后再打包(只会将main/java里面的代码打到包)</p><ul><li>如果是JavaSe的项目,打包成jar包</li><li>如果是JavaWeb的项目,打包成war包</li></ul><p><img src="/images/image-20230917171232490.png" alt="image-20230917171232490"></p><p><img src="/images/image-20230917171235994.png" alt="image-20230917171235994"></p><p>打包后的项目会在target目录下找到</p><p><img src="/images/image-20230917171240035.png" alt="image-20230917171240035"></p><h3 id="install命令" tabindex="-1">install命令 <a class="header-anchor" href="#install命令" aria-label="Permalink to "install命令""></a></h3><p>mvn install,打包后将其安装在本地仓库</p><p><img src="/images/image-20230917171246698.png" alt="image-20230917171246698"></p><p><img src="/images/image-20230917171249920.png" alt="image-20230917171249920"></p><p>安装完毕后,在本地仓库中可以找到itheima_javase_demo的信息</p><p><img src="/images/image-20230917171253868.png" alt="image-20230917171253868"></p><h3 id="小结-5" tabindex="-1">小结 <a class="header-anchor" href="#小结-5" aria-label="Permalink to "小结""></a></h3><ol><li><p>命令作用</p><ul><li>clean 用来清除编译后的文件(target文件夹里面的)<strong>【一般清缓存】</strong></li><li>compile 编译只会编译main里面的内容</li><li>test 执行单元测试,先将main、test中的内容进行编译,然后执行test中的测试方法</li><li>package 打包 (<strong>javaSe-->jar, javaweb-->war</strong>),其实执行打包之前先执行test,然后对项目进行打包</li><li>install 把项目打包之后<strong>安装到本地仓库</strong>,其实执行install之前先执行了打包,然后对项目进行安装到本地仓库</li></ul></li><li><p>生命周期</p><p>当我们执行了install 也会执行compile test package</p></li></ol><h2 id="maven依赖管理-引入依赖" tabindex="-1">Maven依赖管理(引入依赖) <a class="header-anchor" href="#maven依赖管理-引入依赖" aria-label="Permalink to "Maven依赖管理(引入依赖)""></a></h2><h3 id="导入依赖" tabindex="-1">导入依赖 <a class="header-anchor" href="#导入依赖" aria-label="Permalink to "导入依赖""></a></h3><p>导入依赖坐标,无需手动导入jar包就可以引入jar。在pom.xml中使用<code><dependency></code>标签引入依赖。</p><p>做项目/工作里面 都有整套的依赖的, 不需要背诵的.</p><p>去Maven官网找, 赋值,粘贴. <code>http://mvnrepository.com/</code></p><h3 id="导入junit的依赖" tabindex="-1">导入junit的依赖 <a class="header-anchor" href="#导入junit的依赖" aria-label="Permalink to "导入junit的依赖""></a></h3><ul><li>导入junit坐标依赖</li></ul><div class="language-xml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#E1E4E8;"><</span><span style="color:#85E89D;">dependency</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">groupId</span><span style="color:#E1E4E8;">>junit</</span><span style="color:#85E89D;">groupId</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">artifactId</span><span style="color:#E1E4E8;">>junit</</span><span style="color:#85E89D;">artifactId</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">version</span><span style="color:#E1E4E8;">>4.12</</span><span style="color:#85E89D;">version</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">scope</span><span style="color:#E1E4E8;">>test</</span><span style="color:#85E89D;">scope</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"></</span><span style="color:#85E89D;">dependency</span><span style="color:#E1E4E8;">></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292E;"><</span><span style="color:#22863A;">dependency</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">groupId</span><span style="color:#24292E;">>junit</</span><span style="color:#22863A;">groupId</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">artifactId</span><span style="color:#24292E;">>junit</</span><span style="color:#22863A;">artifactId</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">version</span><span style="color:#24292E;">>4.12</</span><span style="color:#22863A;">version</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">scope</span><span style="color:#24292E;">>test</</span><span style="color:#22863A;">scope</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"></</span><span style="color:#22863A;">dependency</span><span style="color:#24292E;">></span></span></code></pre></div><ul><li>进行单元测试</li></ul><div class="language-java vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">java</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#F97583;">import</span><span style="color:#E1E4E8;"> org.junit.Test;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583;">public</span><span style="color:#E1E4E8;"> </span><span style="color:#F97583;">class</span><span style="color:#E1E4E8;"> </span><span style="color:#B392F0;">DemoTest</span><span style="color:#E1E4E8;"> {</span></span>
<span class="line"><span style="color:#E1E4E8;"> @</span><span style="color:#F97583;">Test</span></span>
<span class="line"><span style="color:#E1E4E8;"> </span><span style="color:#F97583;">public</span><span style="color:#E1E4E8;"> </span><span style="color:#F97583;">void</span><span style="color:#E1E4E8;"> </span><span style="color:#B392F0;">test1</span><span style="color:#E1E4E8;">(){</span></span>
<span class="line"><span style="color:#E1E4E8;"> System.out.</span><span style="color:#B392F0;">println</span><span style="color:#E1E4E8;">(</span><span style="color:#9ECBFF;">"test running..."</span><span style="color:#E1E4E8;">);</span></span>
<span class="line"><span style="color:#E1E4E8;"> }</span></span>
<span class="line"><span style="color:#E1E4E8;">}</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#D73A49;">import</span><span style="color:#24292E;"> org.junit.Test;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#D73A49;">public</span><span style="color:#24292E;"> </span><span style="color:#D73A49;">class</span><span style="color:#24292E;"> </span><span style="color:#6F42C1;">DemoTest</span><span style="color:#24292E;"> {</span></span>
<span class="line"><span style="color:#24292E;"> @</span><span style="color:#D73A49;">Test</span></span>
<span class="line"><span style="color:#24292E;"> </span><span style="color:#D73A49;">public</span><span style="color:#24292E;"> </span><span style="color:#D73A49;">void</span><span style="color:#24292E;"> </span><span style="color:#6F42C1;">test1</span><span style="color:#24292E;">(){</span></span>
<span class="line"><span style="color:#24292E;"> System.out.</span><span style="color:#6F42C1;">println</span><span style="color:#24292E;">(</span><span style="color:#032F62;">"test running..."</span><span style="color:#24292E;">);</span></span>
<span class="line"><span style="color:#24292E;"> }</span></span>
<span class="line"><span style="color:#24292E;">}</span></span></code></pre></div><h3 id="导入servlet的依赖" tabindex="-1">导入servlet的依赖 <a class="header-anchor" href="#导入servlet的依赖" aria-label="Permalink to "导入servlet的依赖""></a></h3><ul><li>创建Servlet,但是发现报错,原因是没有导入Servlet的坐标依赖</li></ul><p><img src="/images/image-20230917171301741.png" alt="image-20230917171301741"></p><ul><li>导入Servlet的坐标依赖</li></ul><div class="language-xml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#E1E4E8;"><</span><span style="color:#85E89D;">dependency</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">groupId</span><span style="color:#E1E4E8;">>javax.servlet</</span><span style="color:#85E89D;">groupId</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">artifactId</span><span style="color:#E1E4E8;">>javax.servlet-api</</span><span style="color:#85E89D;">artifactId</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">version</span><span style="color:#E1E4E8;">>3.1.0</</span><span style="color:#85E89D;">version</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">scope</span><span style="color:#E1E4E8;">>provided</</span><span style="color:#85E89D;">scope</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"></</span><span style="color:#85E89D;">dependency</span><span style="color:#E1E4E8;">></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292E;"><</span><span style="color:#22863A;">dependency</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">groupId</span><span style="color:#24292E;">>javax.servlet</</span><span style="color:#22863A;">groupId</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">artifactId</span><span style="color:#24292E;">>javax.servlet-api</</span><span style="color:#22863A;">artifactId</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">version</span><span style="color:#24292E;">>3.1.0</</span><span style="color:#22863A;">version</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">scope</span><span style="color:#24292E;">>provided</</span><span style="color:#22863A;">scope</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"></</span><span style="color:#22863A;">dependency</span><span style="color:#24292E;">></span></span></code></pre></div><ul><li>原有报错的Servlet恢复正常</li></ul><p><img src="/images/image-20230917171306798.png" alt="image-20230917171306798"></p><h3 id="依赖范围" tabindex="-1">依赖范围 <a class="header-anchor" href="#依赖范围" aria-label="Permalink to "依赖范围""></a></h3><p><img src="/images/image-20230917171310809.png" alt="image-20230917171310809"></p><ul><li><p>compile 编译、测试、运行,A在编译时依赖B,并且在测试和运行时也依赖</p><p>例如:strus-core、spring-beans, C3P0,Druid。打到war包或jar包</p></li><li><p><strong>provided 编译、和测试有效</strong>,A在编译和测试时需要B</p><p>例如:servlet-api就是编译和测试有用,在运行时不用(tomcat容器已提供)</p><p>不会打到war</p></li><li><p>runtime:测试运行有效,</p><p>例如:jdbc驱动包 ,在开发代码中针对java的jdbc接口开发,编译不用</p><p>在运行和测试时需要通过jdbc驱动包(mysql驱动)连接数据库,需要的</p><p>会打到war</p></li><li><p>test:只是测试有效,只在单元测试类中用</p><p>例如:junit</p><p>不会打到war</p></li><li><p>按照依赖强度,由强到弱来排序:(理解)</p><p>compile> provided> runtime> test</p></li></ul><h3 id="小结-6" tabindex="-1">小结 <a class="header-anchor" href="#小结-6" aria-label="Permalink to "小结""></a></h3><ol><li><p>坐标不需要背, 做项目时候/工作开发 都有整套的坐标. 如果是导入一些特定, 可以查阅网站,直接拷贝</p></li><li><p>作用范围</p><ul><li>compile 编译、测试、打包运行部署 有效 【默认】</li><li><strong>provided 编译, 测试 有效. 打包运行部署 无效</strong></li><li>runtime 测试、打包运行部署 有效 编译无效</li><li>test 只是测试有效,只在单元测试类中用</li></ul></li><li><p>Servlet,JSP 这类jar 需要加上provided , 因为部署到Tomcat里面. tomcat里面有, 如果没有加上provided , 可能会导致jar 冲突</p><p>单元测试的 建议加上test</p></li></ol><h2 id="maven插件-了解" tabindex="-1">Maven插件(了解) <a class="header-anchor" href="#maven插件-了解" aria-label="Permalink to "Maven插件(了解)""></a></h2><p>Maven是一个核心引擎,提供了基本的项目处理能力和建设过程的管理,以及一系列的插件是用来执行实际建设任务。maven插件可以完成一些特定的功能。例如,集成jdk插件可以方便的修改项目的编译环境;集成tomcat插件后,无需安装tomcat服务器就可以运行tomcat进行项目的发布与测试。在pom.xml中通过plugin标签引入maven的功能插件。</p><h3 id="jdk编译版本的插件【了解】" tabindex="-1">JDK编译版本的插件【了解】 <a class="header-anchor" href="#jdk编译版本的插件【了解】" aria-label="Permalink to "JDK编译版本的插件【了解】""></a></h3><div class="language-xml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#6A737D;"><!--jdk编译插件--></span></span>
<span class="line"><span style="color:#E1E4E8;"><</span><span style="color:#85E89D;">plugin</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">groupId</span><span style="color:#E1E4E8;">>org.apache.maven.plugins</</span><span style="color:#85E89D;">groupId</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">artifactId</span><span style="color:#E1E4E8;">>maven-compiler-plugin</</span><span style="color:#85E89D;">artifactId</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">version</span><span style="color:#E1E4E8;">>3.2</</span><span style="color:#85E89D;">version</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">configuration</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">source</span><span style="color:#E1E4E8;">>1.8</</span><span style="color:#85E89D;">source</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">target</span><span style="color:#E1E4E8;">>1.8</</span><span style="color:#85E89D;">target</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">encoding</span><span style="color:#E1E4E8;">>utf-8</</span><span style="color:#85E89D;">encoding</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">configuration</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"></</span><span style="color:#85E89D;">plugin</span><span style="color:#E1E4E8;">></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#6A737D;"><!--jdk编译插件--></span></span>
<span class="line"><span style="color:#24292E;"><</span><span style="color:#22863A;">plugin</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">groupId</span><span style="color:#24292E;">>org.apache.maven.plugins</</span><span style="color:#22863A;">groupId</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">artifactId</span><span style="color:#24292E;">>maven-compiler-plugin</</span><span style="color:#22863A;">artifactId</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">version</span><span style="color:#24292E;">>3.2</</span><span style="color:#22863A;">version</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">configuration</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">source</span><span style="color:#24292E;">>1.8</</span><span style="color:#22863A;">source</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">target</span><span style="color:#24292E;">>1.8</</span><span style="color:#22863A;">target</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">encoding</span><span style="color:#24292E;">>utf-8</</span><span style="color:#22863A;">encoding</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">configuration</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"></</span><span style="color:#22863A;">plugin</span><span style="color:#24292E;">></span></span></code></pre></div><h3 id="tomcat7服务端的插件-部署项目" tabindex="-1">Tomcat7服务端的插件(部署项目) <a class="header-anchor" href="#tomcat7服务端的插件-部署项目" aria-label="Permalink to "Tomcat7服务端的插件(部署项目)""></a></h3><ul><li>添加tomcat7插件</li></ul><div class="language-xml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#E1E4E8;"><</span><span style="color:#85E89D;">plugins</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">plugin</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">groupId</span><span style="color:#E1E4E8;">>org.apache.tomcat.maven</</span><span style="color:#85E89D;">groupId</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">artifactId</span><span style="color:#E1E4E8;">>tomcat7-maven-plugin</</span><span style="color:#85E89D;">artifactId</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">configuration</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </span><span style="color:#6A737D;"><!-- 指定端口 --></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">port</span><span style="color:#E1E4E8;">>82</</span><span style="color:#85E89D;">port</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </span><span style="color:#6A737D;"><!-- 请求路径 --></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">path</span><span style="color:#E1E4E8;">>/</</span><span style="color:#85E89D;">path</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">configuration</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">plugin</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"></</span><span style="color:#85E89D;">plugins</span><span style="color:#E1E4E8;">></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292E;"><</span><span style="color:#22863A;">plugins</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">plugin</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">groupId</span><span style="color:#24292E;">>org.apache.tomcat.maven</</span><span style="color:#22863A;">groupId</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">artifactId</span><span style="color:#24292E;">>tomcat7-maven-plugin</</span><span style="color:#22863A;">artifactId</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">configuration</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </span><span style="color:#6A737D;"><!-- 指定端口 --></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">port</span><span style="color:#24292E;">>82</</span><span style="color:#22863A;">port</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </span><span style="color:#6A737D;"><!-- 请求路径 --></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">path</span><span style="color:#24292E;">>/</</span><span style="color:#22863A;">path</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">configuration</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">plugin</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"></</span><span style="color:#22863A;">plugins</span><span style="color:#24292E;">></span></span></code></pre></div><blockquote><p>注意: Maven的中央仓库中只有Tomcat7.X版本的插件,而之前我们使用的是8.X的版本,如果想使Tomcat8.X的插件可以去其他第三方仓库进行寻找,或者使用IDEA集成外部Tomcat8极其以上版本,进行项目的发布。</p></blockquote><h3 id="小结-7" tabindex="-1">小结 <a class="header-anchor" href="#小结-7" aria-label="Permalink to "小结""></a></h3><div class="language-xml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#E1E4E8;"><</span><span style="color:#85E89D;">build</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">plugins</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">plugin</span><span style="color:#E1E4E8;">></</span><span style="color:#85E89D;">plugin</span><span style="color:#E1E4E8;">> </span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">plugin</span><span style="color:#E1E4E8;">></</span><span style="color:#85E89D;">plugin</span><span style="color:#E1E4E8;">> </span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">plugins</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"></</span><span style="color:#85E89D;">build</span><span style="color:#E1E4E8;">></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292E;"><</span><span style="color:#22863A;">build</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">plugins</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">plugin</span><span style="color:#24292E;">></</span><span style="color:#22863A;">plugin</span><span style="color:#24292E;">> </span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">plugin</span><span style="color:#24292E;">></</span><span style="color:#22863A;">plugin</span><span style="color:#24292E;">> </span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">plugins</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"></</span><span style="color:#22863A;">build</span><span style="color:#24292E;">></span></span></code></pre></div><h2 id="maven配置修改" tabindex="-1">maven配置修改 <a class="header-anchor" href="#maven配置修改" aria-label="Permalink to "maven配置修改""></a></h2><h3 id="修改不使用骨架创建maven项目的默认编译版本" tabindex="-1">修改不使用骨架创建maven项目的默认编译版本 <a class="header-anchor" href="#修改不使用骨架创建maven项目的默认编译版本" aria-label="Permalink to "修改不使用骨架创建maven项目的默认编译版本""></a></h3><ol><li><p>不使用骨架创建的maven项目的默认编译版本是1.5或者1.4版本</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><profile> </span></span>
<span class="line"><span style="color:#e1e4e8;"> <id>jdk1.8</id></span></span>
<span class="line"><span style="color:#e1e4e8;"> <activation> </span></span>
<span class="line"><span style="color:#e1e4e8;"> <activeByDefault>true</activeByDefault></span></span>
<span class="line"><span style="color:#e1e4e8;"> <jdk>1.8</jdk> </span></span>
<span class="line"><span style="color:#e1e4e8;"> </activation></span></span>
<span class="line"><span style="color:#e1e4e8;"> <properties></span></span>
<span class="line"><span style="color:#e1e4e8;"> <maven.compiler.source>1.8</maven.compiler.source></span></span>
<span class="line"><span style="color:#e1e4e8;"> <maven.compiler.target>1.8</maven.compiler.target></span></span>
<span class="line"><span style="color:#e1e4e8;"> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion></span></span>
<span class="line"><span style="color:#e1e4e8;"> <encoding>UTF-8</encoding></span></span>
<span class="line"><span style="color:#e1e4e8;"> </properties> </span></span>
<span class="line"><span style="color:#e1e4e8;"></profile></span></span>
<span class="line"><span style="color:#e1e4e8;">将上述标签内容添加到settings文件的<profiles>标签中</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><profile> </span></span>
<span class="line"><span style="color:#24292e;"> <id>jdk1.8</id></span></span>
<span class="line"><span style="color:#24292e;"> <activation> </span></span>
<span class="line"><span style="color:#24292e;"> <activeByDefault>true</activeByDefault></span></span>
<span class="line"><span style="color:#24292e;"> <jdk>1.8</jdk> </span></span>
<span class="line"><span style="color:#24292e;"> </activation></span></span>
<span class="line"><span style="color:#24292e;"> <properties></span></span>
<span class="line"><span style="color:#24292e;"> <maven.compiler.source>1.8</maven.compiler.source></span></span>
<span class="line"><span style="color:#24292e;"> <maven.compiler.target>1.8</maven.compiler.target></span></span>
<span class="line"><span style="color:#24292e;"> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion></span></span>
<span class="line"><span style="color:#24292e;"> <encoding>UTF-8</encoding></span></span>
<span class="line"><span style="color:#24292e;"> </properties> </span></span>
<span class="line"><span style="color:#24292e;"></profile></span></span>
<span class="line"><span style="color:#24292e;">将上述标签内容添加到settings文件的<profiles>标签中</span></span></code></pre></div></li></ol><h3 id="彻底解决引入依赖的时候卡、报错" tabindex="-1">彻底解决引入依赖的时候卡、报错 <a class="header-anchor" href="#彻底解决引入依赖的时候卡、报错" aria-label="Permalink to "彻底解决引入依赖的时候卡、报错""></a></h3><p>修改settings.xml文件,添加如下代码</p><div class="language-xml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#E1E4E8;"><</span><span style="color:#85E89D;">mirrors</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">mirror</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">>alimaven</</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">name</span><span style="color:#E1E4E8;">>aliyun maven</</span><span style="color:#85E89D;">name</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">>http://maven.aliyun.com/nexus/content/groups/public/</</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">mirrorOf</span><span style="color:#E1E4E8;">>central</</span><span style="color:#85E89D;">mirrorOf</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">mirror</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">mirror</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">>uk</</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">mirrorOf</span><span style="color:#E1E4E8;">>central</</span><span style="color:#85E89D;">mirrorOf</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">name</span><span style="color:#E1E4E8;">>Human Readable Name for this Mirror.</</span><span style="color:#85E89D;">name</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">>http://uk.maven.org/maven2/</</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">mirror</span><span style="color:#E1E4E8;">></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">mirror</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">>CN</</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">name</span><span style="color:#E1E4E8;">>OSChina Central</</span><span style="color:#85E89D;">name</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">>http://maven.oschina.net/content/groups/public/</</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">mirrorOf</span><span style="color:#E1E4E8;">>central</</span><span style="color:#85E89D;">mirrorOf</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">mirror</span><span style="color:#E1E4E8;">></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">mirror</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">>nexus</</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">name</span><span style="color:#E1E4E8;">>internal nexus repository</</span><span style="color:#85E89D;">name</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">>http://repo.maven.apache.org/maven2</</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">mirrorOf</span><span style="color:#E1E4E8;">>central</</span><span style="color:#85E89D;">mirrorOf</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">mirror</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">mirrors</span><span style="color:#E1E4E8;">></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292E;"><</span><span style="color:#22863A;">mirrors</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">mirror</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">id</span><span style="color:#24292E;">>alimaven</</span><span style="color:#22863A;">id</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">name</span><span style="color:#24292E;">>aliyun maven</</span><span style="color:#22863A;">name</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">url</span><span style="color:#24292E;">>http://maven.aliyun.com/nexus/content/groups/public/</</span><span style="color:#22863A;">url</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">mirrorOf</span><span style="color:#24292E;">>central</</span><span style="color:#22863A;">mirrorOf</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">mirror</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">mirror</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">id</span><span style="color:#24292E;">>uk</</span><span style="color:#22863A;">id</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">mirrorOf</span><span style="color:#24292E;">>central</</span><span style="color:#22863A;">mirrorOf</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">name</span><span style="color:#24292E;">>Human Readable Name for this Mirror.</</span><span style="color:#22863A;">name</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">url</span><span style="color:#24292E;">>http://uk.maven.org/maven2/</</span><span style="color:#22863A;">url</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">mirror</span><span style="color:#24292E;">></span></span>
<span class="line"></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">mirror</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">id</span><span style="color:#24292E;">>CN</</span><span style="color:#22863A;">id</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">name</span><span style="color:#24292E;">>OSChina Central</</span><span style="color:#22863A;">name</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">url</span><span style="color:#24292E;">>http://maven.oschina.net/content/groups/public/</</span><span style="color:#22863A;">url</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">mirrorOf</span><span style="color:#24292E;">>central</</span><span style="color:#22863A;">mirrorOf</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">mirror</span><span style="color:#24292E;">></span></span>
<span class="line"></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">mirror</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">id</span><span style="color:#24292E;">>nexus</</span><span style="color:#22863A;">id</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">name</span><span style="color:#24292E;">>internal nexus repository</</span><span style="color:#22863A;">name</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">url</span><span style="color:#24292E;">>http://repo.maven.apache.org/maven2</</span><span style="color:#22863A;">url</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">mirrorOf</span><span style="color:#24292E;">>central</</span><span style="color:#22863A;">mirrorOf</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">mirror</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">mirrors</span><span style="color:#24292E;">></span></span></code></pre></div><h3 id="注意点" tabindex="-1">注意点 <a class="header-anchor" href="#注意点" aria-label="Permalink to "注意点""></a></h3><ol><li>引入依赖之后,要检查依赖是否引入成功</li></ol><p><img src="/images/image-20230917171716634.png" alt="image-20230917171716634"></p><ol start="2"><li><p>如果dependencies中大块报红</p><ol><li>先使用cleanLastUpdated文件,进行清理。清完之后刷新</li><li>检查自己的maven配置是否正确</li></ol><p><img src="/images/image-20230917171721680.png" alt="image-20230917171721680"></p><ol start="3"><li>检查settings.xml中的本地仓库路径配置是否正确</li></ol><p><img src="/images/image-20230917171731555.png" alt="image-20230917171731555"></p><ol start="4"><li>将所有的依赖删除,接着一个一个依赖添加,添加一个就刷新一下,看是否添加成功,如果发现了哪个依赖报错,很有可能是因为你的本地仓库中没有该版本,所以我们可以尝试切换版本</li></ol></li></ol><h2 id="maven私服【了解】" tabindex="-1">maven私服【了解】 <a class="header-anchor" href="#maven私服【了解】" aria-label="Permalink to "maven私服【了解】""></a></h2><h3 id="私服概述" tabindex="-1">私服概述 <a class="header-anchor" href="#私服概述" aria-label="Permalink to "私服概述""></a></h3><p><strong>公司在自己的局域网内搭建自己的远程仓库服务器,称为私服</strong>, 私服服务器即是公司内部的 maven 远程仓库, 每个员工的电脑上安装 maven 软件并且连接私服服务器,员工将自己开发的项目打成 jar 并发布到私服服务器,其它项目组从私服服务器下载所依赖的构件(jar)。私服还充当一个代理服务器,当私服上没有 jar 包会从互联网中央仓库自动下载,如下 图 :</p><p><img src="/images/image-20230917171736830.png" alt="image-20230917171736830"></p><blockquote><p>私服也属于远程仓库的一种,一般来说,私服仓库搭建在公司局域网内,专供公司内部开发人员提供服务,不是对外使用的</p></blockquote><p>一般Maven下载jar包的步骤是:<code>本地仓库(本机)--->私服(局域网)--->中心仓库(外部网络)</code></p><h3 id="私服搭建" tabindex="-1">私服搭建 <a class="header-anchor" href="#私服搭建" aria-label="Permalink to "私服搭建""></a></h3><h4 id="下载-nexus" tabindex="-1">下载 nexus <a class="header-anchor" href="#下载-nexus" aria-label="Permalink to "下载 nexus""></a></h4><p>Nexus 是 Maven 仓库管理器, 通过 nexus 可以搭建 maven 仓库,同时 nexus 还提供强大的仓库管理功能,构件搜索功能等。 下载地址: <a href="http://www.sonatype.org/nexus/archived/" target="_blank" rel="noreferrer">http://www.sonatype.org/nexus/archived/</a></p><p>下载: nexus-2.12.0-01-bundle.zip</p><p><img src="/images/image-20230917171838275.png" alt="image-20230917171838275"></p><h4 id="安装-nexus" tabindex="-1">安装 nexus <a class="header-anchor" href="#安装-nexus" aria-label="Permalink to "安装 nexus""></a></h4><p>解压 nexus-2.12.0-01-bundle.zip,进入 bin 目录:</p><p><img src="/images/image-20230917171842690.png" alt="image-20230917171842690"></p><p>以管理员权限运行命令行,进入 bin 目录,执行 nexus.bat install</p><p><img src="/images/image-20230917171846939.png" alt="image-20230917171846939"></p><p>安装成功在服务中查看有 nexus 服务:</p><p><img src="/images/image-20230917171850718.png" alt="image-20230917171850718"></p><h4 id="卸载nexus" tabindex="-1">卸载nexus <a class="header-anchor" href="#卸载nexus" aria-label="Permalink to "卸载nexus""></a></h4><p>cmd 进入 nexus 的 bin 目录,执行: nexus.bat uninstall</p><p><img src="/images/image-20230917171854949.png" alt="image-20230917171854949"></p><h4 id="启动-nexus" tabindex="-1">启动 nexus <a class="header-anchor" href="#启动-nexus" aria-label="Permalink to "启动 nexus""></a></h4><ul><li><p>方式一</p><p>cmd 进入 bin 目录,执行 nexus.bat start</p></li><li><p>方式二</p><p>直接启动 nexus 服务</p><p><img src="/images/image-20230917171900392.png" alt="image-20230917171900392"></p></li></ul><p>登录</p><ul><li><p>访问: <code>http://localhost:8081/nexus/</code></p><blockquote><p>查看 nexus 的配置文件 conf/nexus.properties ,里面有端口号</p></blockquote></li></ul><p><img src="/images/image-20230917171906111.png" alt="image-20230917171906111"></p><ul><li>点击右上角的 Log in,输入账号和密码 登陆 (账号admin,密码admin123 )</li></ul><p><img src="/images/image-20230917171911308.png" alt="image-20230917171911308"></p><ul><li>登录成功</li></ul><p><img src="/images/image-20230917171915945.png" alt="image-20230917171915945"></p><h4 id="仓库类型" tabindex="-1">仓库类型 <a class="header-anchor" href="#仓库类型" aria-label="Permalink to "仓库类型""></a></h4><p><img src="/images/image-20230917171919860.png" alt="image-20230917171919860"></p><p><img src="/images/image-20230917171924615.png" alt="image-20230917171924615"></p><p><img src="/images/image-20230917171929705.png" alt="image-20230917171929705"></p><p>nexus 的仓库有 4 种类型:</p><p><img src="/images/image-20230917171933551.png" alt="image-20230917171933551"></p><ol><li>hosted,宿主仓库, 部署自己的 jar 到这个类型的仓库,包括 releases 和 snapshot 两部分, Releases 公司内部发布版本仓库、 Snapshots 公司内部测试版本仓库</li><li>proxy,代理仓库, 用于代理远程的公共仓库,如 maven 中央仓库,用户连接私服,私服自动去中央仓库下载 jar 包或者插件。</li><li>group,仓库组,用来合并多个 hosted/proxy 仓库,通常我们配置自己的 maven 连接仓库组。</li><li>virtual(虚拟):兼容 Maven1 版本的 jar 或者插件</li></ol><h4 id="小结-8" tabindex="-1">小结 <a class="header-anchor" href="#小结-8" aria-label="Permalink to "小结""></a></h4><ol><li><p>对着文档搭建一下就OK</p></li><li><p>安装的时候需要以<code>管理员</code> 身份</p></li><li><p>路径不要有中文</p></li></ol><h3 id="私服使用" tabindex="-1">私服使用 <a class="header-anchor" href="#私服使用" aria-label="Permalink to "私服使用""></a></h3><h4 id="将项目发布到私服" tabindex="-1">将项目发布到私服 <a class="header-anchor" href="#将项目发布到私服" aria-label="Permalink to "将项目发布到私服""></a></h4><h5 id="需求" tabindex="-1">需求 <a class="header-anchor" href="#需求" aria-label="Permalink to "需求""></a></h5><p>企业中多个团队协作开发通常会将一些公用的组件、开发模块等发布到私服供其它团队或模块开发人员使用。 本例子假设多团队分别开发 . 某个团队开发完在common_utils, 将 common_utils发布到私服供 其它团队使用.</p><h5 id="配置" tabindex="-1">配置 <a class="header-anchor" href="#配置" aria-label="Permalink to "配置""></a></h5><p>第一步: 需要在客户端即部署common_utils工程的电脑上配置 maven环境,并修改 settings.xml文件(Maven配置文件), 配置连接私服的用户和密码 。此用户名和密码用于私服校验,因为私服需要知道上传的账号和密码是否和私服中的账号和密码一致 (配置到<code><servers></code>标签下)</p><div class="language-xml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#E1E4E8;"><</span><span style="color:#85E89D;">server</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">>releases</</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">username</span><span style="color:#E1E4E8;">>admin</</span><span style="color:#85E89D;">username</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">password</span><span style="color:#E1E4E8;">>admin123</</span><span style="color:#85E89D;">password</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"></</span><span style="color:#85E89D;">server</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"><</span><span style="color:#85E89D;">server</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">>snapshots</</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">username</span><span style="color:#E1E4E8;">>admin</</span><span style="color:#85E89D;">username</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">password</span><span style="color:#E1E4E8;">>admin123</</span><span style="color:#85E89D;">password</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"></</span><span style="color:#85E89D;">server</span><span style="color:#E1E4E8;">></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292E;"><</span><span style="color:#22863A;">server</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">id</span><span style="color:#24292E;">>releases</</span><span style="color:#22863A;">id</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">username</span><span style="color:#24292E;">>admin</</span><span style="color:#22863A;">username</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">password</span><span style="color:#24292E;">>admin123</</span><span style="color:#22863A;">password</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"></</span><span style="color:#22863A;">server</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"><</span><span style="color:#22863A;">server</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">id</span><span style="color:#24292E;">>snapshots</</span><span style="color:#22863A;">id</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">username</span><span style="color:#24292E;">>admin</</span><span style="color:#22863A;">username</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">password</span><span style="color:#24292E;">>admin123</</span><span style="color:#22863A;">password</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"></</span><span style="color:#22863A;">server</span><span style="color:#24292E;">></span></span></code></pre></div><p>releases: 连接发布版本项目仓库 snapshots: 连接测试版本项目仓库</p><p><img src="/images/image-20230917171940089.png" alt="image-20230917171940089"></p><p>第二步: 在需要发布配置项目 pom.xml . 配置私服仓库的地址,本公司的自己的 jar 包会上传到私服的宿主仓库,根据工程的版本号决定上传到哪个宿主仓库,如果版本为 release 则上传到私服的 release 仓库,如果版本为snapshot 则上传到私服的 snapshot 仓库 .</p><div class="language-xml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#E1E4E8;"><</span><span style="color:#85E89D;">distributionManagement</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">repository</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">>releases</</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">>http://localhost:8081/nexus/content/repositories/releases/</</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">repository</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">snapshotRepository</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">>snapshots</</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">>http://localhost:8081/nexus/content/repositories/snapshots/</</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">snapshotRepository</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"></</span><span style="color:#85E89D;">distributionManagement</span><span style="color:#E1E4E8;">></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292E;"><</span><span style="color:#22863A;">distributionManagement</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">repository</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">id</span><span style="color:#24292E;">>releases</</span><span style="color:#22863A;">id</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">url</span><span style="color:#24292E;">>http://localhost:8081/nexus/content/repositories/releases/</</span><span style="color:#22863A;">url</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">repository</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">snapshotRepository</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">id</span><span style="color:#24292E;">>snapshots</</span><span style="color:#22863A;">id</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">url</span><span style="color:#24292E;">>http://localhost:8081/nexus/content/repositories/snapshots/</</span><span style="color:#22863A;">url</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">snapshotRepository</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"></</span><span style="color:#22863A;">distributionManagement</span><span style="color:#24292E;">></span></span></code></pre></div><ul><li>注意: pom.xml 这里<code><id></code> 和 settings.xml 配置<code><id></code>对应!</li></ul><h5 id="测试" tabindex="-1">测试 <a class="header-anchor" href="#测试" aria-label="Permalink to "测试""></a></h5><p>1、 首先启动 nexus 2、 对 common_utils工程执行 deploy 命令</p><p>根据本项目pom.xml中version定义决定发布到哪个仓库,如果version定义为snapshot,执行 deploy后查看 nexus 的 snapshot仓库, 如果 version定义为 release则项目将发布到 nexus的 release 仓库,本项目将发布到 snapshot 仓库:</p><p><img src="/images/image-20191222211914094.png" alt="image-20191222211914094"></p><h4 id="从私服下载-jar-包" tabindex="-1">从私服下载 jar 包 <a class="header-anchor" href="#从私服下载-jar-包" aria-label="Permalink to "从私服下载 jar 包""></a></h4><h5 id="需求-1" tabindex="-1">需求 <a class="header-anchor" href="#需求-1" aria-label="Permalink to "需求""></a></h5><p>没有配置 nexus 之前,如果本地仓库没有,去中央仓库下载,通常在企业中会在局域网内部署一台私服服务器, 有了私服本地项目首先去本地仓库找 jar,如果没有找到则连接私服从私服下载 jar 包,如果私服没有 jar 包私服同时作为代理服务器从中央仓库下载 jar 包,这样做的好处是一方面由私服对公司项目的依赖 jar 包统一管理,一方面提高下载速度, 项目连接私服下载 jar 包的速度要比项目连接中央仓库的速度快的多。</p><p>本例子测试从私服下载 commons-utils工程 jar 包。</p><h5 id="在-settings-xml-中配置仓库" tabindex="-1">在 settings.xml 中配置仓库 <a class="header-anchor" href="#在-settings-xml-中配置仓库" aria-label="Permalink to "在 settings.xml 中配置仓库""></a></h5><p>在客户端的 settings.xml 中配置私服的仓库,由于 setting.xml 中没有 repositories 的配置标签需要使用 profile 定义仓库。(<strong>配置在<code><profiles></code>标签下</strong>)</p><div class="language-xml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#E1E4E8;"><</span><span style="color:#85E89D;">profile</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </span><span style="color:#6A737D;"><!--profile 的 id--></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">>dev</</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">repositories</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">repository</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </span><span style="color:#6A737D;"><!--仓库 id, repositories 可以配置多个仓库,保证 id 不重复--></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">>nexus</</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </span><span style="color:#6A737D;"><!--仓库地址,即 nexus 仓库组的地址--></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">>http://localhost:8081/nexus/content/groups/public/</</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </span><span style="color:#6A737D;"><!--是否下载 releases 构件--></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">releases</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">enabled</span><span style="color:#E1E4E8;">>true</</span><span style="color:#85E89D;">enabled</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">releases</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </span><span style="color:#6A737D;"><!--是否下载 snapshots 构件--></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">snapshots</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">enabled</span><span style="color:#E1E4E8;">>true</</span><span style="color:#85E89D;">enabled</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">snapshots</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">repository</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">repositories</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">pluginRepositories</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </span><span style="color:#6A737D;"><!-- 插件仓库, maven 的运行依赖插件,也需要从私服下载插件 --></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">pluginRepository</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </span><span style="color:#6A737D;"><!-- 插件仓库的 id 不允许重复,如果重复后边配置会覆盖前边 --></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">>public</</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">name</span><span style="color:#E1E4E8;">>Public Repositories</</span><span style="color:#85E89D;">name</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">>http://localhost:8081/nexus/content/groups/public/</</span><span style="color:#85E89D;">url</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">pluginRepository</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> </</span><span style="color:#85E89D;">pluginRepositories</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"></</span><span style="color:#85E89D;">profile</span><span style="color:#E1E4E8;">></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292E;"><</span><span style="color:#22863A;">profile</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </span><span style="color:#6A737D;"><!--profile 的 id--></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">id</span><span style="color:#24292E;">>dev</</span><span style="color:#22863A;">id</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">repositories</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">repository</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </span><span style="color:#6A737D;"><!--仓库 id, repositories 可以配置多个仓库,保证 id 不重复--></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">id</span><span style="color:#24292E;">>nexus</</span><span style="color:#22863A;">id</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </span><span style="color:#6A737D;"><!--仓库地址,即 nexus 仓库组的地址--></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">url</span><span style="color:#24292E;">>http://localhost:8081/nexus/content/groups/public/</</span><span style="color:#22863A;">url</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </span><span style="color:#6A737D;"><!--是否下载 releases 构件--></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">releases</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">enabled</span><span style="color:#24292E;">>true</</span><span style="color:#22863A;">enabled</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">releases</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </span><span style="color:#6A737D;"><!--是否下载 snapshots 构件--></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">snapshots</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">enabled</span><span style="color:#24292E;">>true</</span><span style="color:#22863A;">enabled</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">snapshots</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">repository</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">repositories</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">pluginRepositories</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </span><span style="color:#6A737D;"><!-- 插件仓库, maven 的运行依赖插件,也需要从私服下载插件 --></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">pluginRepository</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </span><span style="color:#6A737D;"><!-- 插件仓库的 id 不允许重复,如果重复后边配置会覆盖前边 --></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">id</span><span style="color:#24292E;">>public</</span><span style="color:#22863A;">id</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">name</span><span style="color:#24292E;">>Public Repositories</</span><span style="color:#22863A;">name</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">url</span><span style="color:#24292E;">>http://localhost:8081/nexus/content/groups/public/</</span><span style="color:#22863A;">url</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">pluginRepository</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> </</span><span style="color:#22863A;">pluginRepositories</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"></</span><span style="color:#22863A;">profile</span><span style="color:#24292E;">></span></span></code></pre></div><p>使用 profile 定义仓库需要激活才可生效。</p><div class="language-xml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#E1E4E8;"><</span><span style="color:#85E89D;">activeProfiles</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">activeProfile</span><span style="color:#E1E4E8;">>dev</</span><span style="color:#85E89D;">activeProfile</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"></</span><span style="color:#85E89D;">activeProfiles</span><span style="color:#E1E4E8;">></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292E;"><</span><span style="color:#22863A;">activeProfiles</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">activeProfile</span><span style="color:#24292E;">>dev</</span><span style="color:#22863A;">activeProfile</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"></</span><span style="color:#22863A;">activeProfiles</span><span style="color:#24292E;">></span></span></code></pre></div><h5 id="测试从私服下载-jar-包" tabindex="-1">测试从私服下载 jar 包 <a class="header-anchor" href="#测试从私服下载-jar-包" aria-label="Permalink to "测试从私服下载 jar 包""></a></h5><ul><li><p>删掉本地仓库的day01_javase_02</p></li><li><p>编译依赖day01_javase_02的工程</p></li></ul><p><img src="/images/image-20191222212314528.png" alt="image-20191222212314528"></p><ul><li>出现如下日志</li></ul><p><img src="/images/image-20191222212255624.png" alt="image-20191222212255624"></p><h4 id="小结-9" tabindex="-1">小结 <a class="header-anchor" href="#小结-9" aria-label="Permalink to "小结""></a></h4><ol><li>对着文档操作</li></ol><h2 id="maven安装jar" tabindex="-1">maven安装Jar <a class="header-anchor" href="#maven安装jar" aria-label="Permalink to "maven安装Jar""></a></h2><h3 id="把jar安装到本地仓库-掌握" tabindex="-1">把jar安装到本地仓库(掌握) <a class="header-anchor" href="#把jar安装到本地仓库-掌握" aria-label="Permalink to "把jar安装到本地仓库(掌握)""></a></h3><ul><li>随便找一个 jar 包测试, 可以先 CMD进入到 jar 包所在位置,运行</li></ul><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#B392F0;">mvn</span><span style="color:#E1E4E8;"> </span><span style="color:#9ECBFF;">install:install-file</span><span style="color:#E1E4E8;"> </span><span style="color:#79B8FF;">-DgroupId=com.itheima</span><span style="color:#E1E4E8;"> </span><span style="color:#79B8FF;">-DartifactId=nbutil</span><span style="color:#E1E4E8;"> </span><span style="color:#79B8FF;">-Dversion=1.1.37</span><span style="color:#E1E4E8;"> </span><span style="color:#79B8FF;">-Dfile=nbutil-1.1.37.jar</span><span style="color:#E1E4E8;"> </span><span style="color:#79B8FF;">-Dpackaging=jar</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#6F42C1;">mvn</span><span style="color:#24292E;"> </span><span style="color:#032F62;">install:install-file</span><span style="color:#24292E;"> </span><span style="color:#005CC5;">-DgroupId=com.itheima</span><span style="color:#24292E;"> </span><span style="color:#005CC5;">-DartifactId=nbutil</span><span style="color:#24292E;"> </span><span style="color:#005CC5;">-Dversion=1.1.37</span><span style="color:#24292E;"> </span><span style="color:#005CC5;">-Dfile=nbutil-1.1.37.jar</span><span style="color:#24292E;"> </span><span style="color:#005CC5;">-Dpackaging=jar</span></span></code></pre></div><p><img src="/images/image-20230917172054882.png" alt="image-20230917172054882"></p><p><img src="/images/image-20230917172059430.png" alt="image-20230917172059430"></p><h3 id="把jar安装到私服" tabindex="-1">把jar安装到私服 <a class="header-anchor" href="#把jar安装到私服" aria-label="Permalink to "把jar安装到私服""></a></h3><p>需要在 maven 软件的核心配置文件 settings.xml 中配置第三方仓库的 server 信息</p><div class="language-xml vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#E1E4E8;"><</span><span style="color:#85E89D;">server</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">>thirdparty</</span><span style="color:#85E89D;">id</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">username</span><span style="color:#E1E4E8;">>admin</</span><span style="color:#85E89D;">username</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"> <</span><span style="color:#85E89D;">password</span><span style="color:#E1E4E8;">>admin123</</span><span style="color:#85E89D;">password</span><span style="color:#E1E4E8;">></span></span>
<span class="line"><span style="color:#E1E4E8;"></</span><span style="color:#85E89D;">server</span><span style="color:#E1E4E8;">></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292E;"><</span><span style="color:#22863A;">server</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">id</span><span style="color:#24292E;">>thirdparty</</span><span style="color:#22863A;">id</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">username</span><span style="color:#24292E;">>admin</</span><span style="color:#22863A;">username</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"> <</span><span style="color:#22863A;">password</span><span style="color:#24292E;">>admin123</</span><span style="color:#22863A;">password</span><span style="color:#24292E;">></span></span>
<span class="line"><span style="color:#24292E;"></</span><span style="color:#22863A;">server</span><span style="color:#24292E;">></span></span></code></pre></div><p>才能执行一下命令</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#B392F0;">mvn</span><span style="color:#E1E4E8;"> </span><span style="color:#9ECBFF;">deploy:deploy-file</span><span style="color:#E1E4E8;"> </span><span style="color:#79B8FF;">-DgroupId=com.itheima</span><span style="color:#E1E4E8;"> </span><span style="color:#79B8FF;">-DartifactId=nbutil</span><span style="color:#E1E4E8;"> </span><span style="color:#79B8FF;">-Dversion=1.1.37</span><span style="color:#E1E4E8;"> </span><span style="color:#79B8FF;">-Dpackaging=jar</span><span style="color:#E1E4E8;"> </span><span style="color:#79B8FF;">-Dfile=nbutil-1.1.37.jar</span><span style="color:#E1E4E8;"> </span><span style="color:#79B8FF;">-Durl=http://localhost:8081/nexus/content/repositories/thirdparty/</span><span style="color:#E1E4E8;"> </span><span style="color:#79B8FF;">-DrepositoryId=thirdparty</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#6F42C1;">mvn</span><span style="color:#24292E;"> </span><span style="color:#032F62;">deploy:deploy-file</span><span style="color:#24292E;"> </span><span style="color:#005CC5;">-DgroupId=com.itheima</span><span style="color:#24292E;"> </span><span style="color:#005CC5;">-DartifactId=nbutil</span><span style="color:#24292E;"> </span><span style="color:#005CC5;">-Dversion=1.1.37</span><span style="color:#24292E;"> </span><span style="color:#005CC5;">-Dpackaging=jar</span><span style="color:#24292E;"> </span><span style="color:#005CC5;">-Dfile=nbutil-1.1.37.jar</span><span style="color:#24292E;"> </span><span style="color:#005CC5;">-Durl=http://localhost:8081/nexus/content/repositories/thirdparty/</span><span style="color:#24292E;"> </span><span style="color:#005CC5;">-DrepositoryId=thirdparty</span></span></code></pre></div><p><img src="/images/image-20230917172111669.png" alt="image-20230917172111669"></p><p><img src="/images/image-20230917172116531.png" alt="image-20230917172116531"></p><h4 id="参数说明" tabindex="-1">参数说明 <a class="header-anchor" href="#参数说明" aria-label="Permalink to "参数说明""></a></h4><p>DgroupId 和 DartifactId 构成了该 jar 包在 pom.xml 的坐标,项目就是依靠这两个属性定位。自己起名字也行。</p><p>Dfile 表示需要上传的 jar 包的绝对路径。</p><p>Durl 私服上仓库的位置,打开 nexus——>repositories 菜单,可以看到该路径。</p><p>DrepositoryId 服务器的表示 id,在 nexus 的 configuration 可以看到。</p><p>Dversion 表示版本信息。</p><p>关于 jar 包准确的版本:</p><p>包的名字上一般会带版本号,如果没有那可以解压该包,会发现一个叫 MANIFEST.MF 的文件</p><p>这个文件就有描述该包的版本信息。</p><p>比如 Specification-Version: 2.2 可以知道该包的版本了。</p><p>上传成功后,在 nexus 界面点击 3rd party 仓库可以看到这包。</p><h4 id="小结-10" tabindex="-1">小结 <a class="header-anchor" href="#小结-10" aria-label="Permalink to "小结""></a></h4><ol><li>有些jar中央仓库没有(eg:oracle驱动), 从官网/网络上下载下来, 安装到本地仓库. 我们的Maven项目就可以使用了</li><li>具体操作参考文档</li></ol><h3 id="cleanlastupdated-bat" tabindex="-1"><code>cleanLastUpdated.bat</code> <a class="header-anchor" href="#cleanlastupdated-bat" aria-label="Permalink to "`cleanLastUpdated.bat`""></a></h3><p>清理无效jar包脚本</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;">set REPOSITORY_PATH=C:\maven\apache-maven-3.5.2\repository</span></span>
<span class="line"><span style="color:#e1e4e8;">rem 正在搜索...</span></span>
<span class="line"><span style="color:#e1e4e8;">for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\*lastUpdated*"') do (</span></span>
<span class="line"><span style="color:#e1e4e8;"> del /s /q %%i</span></span>
<span class="line"><span style="color:#e1e4e8;">)</span></span>
<span class="line"><span style="color:#e1e4e8;">rem 搜索完毕</span></span>
<span class="line"><span style="color:#e1e4e8;">pause</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;">set REPOSITORY_PATH=C:\maven\apache-maven-3.5.2\repository</span></span>
<span class="line"><span style="color:#24292e;">rem 正在搜索...</span></span>
<span class="line"><span style="color:#24292e;">for /f "delims=" %%i in ('dir /b /s "%REPOSITORY_PATH%\*lastUpdated*"') do (</span></span>
<span class="line"><span style="color:#24292e;"> del /s /q %%i</span></span>
<span class="line"><span style="color:#24292e;">)</span></span>
<span class="line"><span style="color:#24292e;">rem 搜索完毕</span></span>
<span class="line"><span style="color:#24292e;">pause</span></span></code></pre></div><h2 id="pom层次" tabindex="-1">Pom层次 <a class="header-anchor" href="#pom层次" aria-label="Permalink to "Pom层次""></a></h2><h3 id="pom文件简介" tabindex="-1">Pom文件简介 <a class="header-anchor" href="#pom文件简介" aria-label="Permalink to "Pom文件简介""></a></h3><pre><code> 而 pom.xml 主要描述了项目的基本信息,用于描述项目如何构建,声明项目依赖等等,是项目级别的配置文件,执行任务或目标时,Maven 会在当前目录中查找 POM,然后读取 POM,获取所需的配置信息,然后执行目标。
pom(project object model)即项目对象模型,maven 把一个项目的结构和内容抽象成一个模型,在 xml 文件中进行声明,以方便进行构建和描述。
</code></pre><h3 id="super-pom" tabindex="-1">Super POM <a class="header-anchor" href="#super-pom" aria-label="Permalink to "Super POM""></a></h3><p>经过我们前面的学习,我们看到 Maven 在构建过程中有很多默认的设定。例如:源文件存放的目录、测试源文件存放的目录、构建输出的目录……等等。但是其实这些要素也都是被 Maven 定义过的。定义的位置就是:<strong>超级 POM</strong>。</p><p>关于超级 POM,Maven 官网是这样介绍的:</p><blockquote><p>The Super POM is Maven's default POM. All POMs extend the Super POM unless explicitly set, meaning the configuration specified in the Super POM is inherited by the POMs you created for your projects.</p><p>译文:Super POM 是 Maven 的默认 POM。除非明确设置,否则所有 POM 都扩展 Super POM,这意味着 Super POM 中指定的配置由您为项目创建的 POM 继承。</p></blockquote><p>所以我们自己的 POM 即使没有明确指定一个父工程(父 POM),其实也默认继承了超级 POM。就好比一个 Java 类默认继承了 Object 类。</p><p>这个POM文件可以在 <a href="https://maven.apache.org/ref/3.8.1/maven-model-builder/super-pom.html" target="_blank" rel="noreferrer">[Maven Super Pom](Maven Model Builder – Super POM)</a> 找到。</p><p>也可以在 本地这个路径找到 <code>$MAVEN_HOME/lib/maven-model-builder-3.8.1.jar!/org/apache/maven/model/pom-4.0.0.xml</code></p><p><strong>1. repositories</strong></p><p>定义了一个名叫 central的repository,value是 '<a href="https://repo.maven.apache.org/maven2" target="_blank" rel="noreferrer">https://repo.maven.apache.org/maven2</a>',可以从这个地址拉下来dependency。</p><p><strong>2. pluginRepositories</strong></p><p>默认 plugin的 repositories</p><p><strong>3. build</strong></p><p>设置了一些默认的路径,其中还定义了 几个插件,不过<a href="https://maven.apache.org/ref/3.8.1/maven-model-builder/super-pom.html" target="_blank" rel="noreferrer">Maven官方</a>也提醒,未来的版本会去掉。</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><pluginManagement></span></span>
<span class="line"><span style="color:#e1e4e8;"> <!-- NOTE: These plugins will be removed from future versions of the super POM --></span></span>
<span class="line"><span style="color:#e1e4e8;"> <!-- They are kept for the moment as they are very unlikely to conflict with lifecycle mappings (MNG-4453) --></span></span>
<span class="line"><span style="color:#e1e4e8;"></pluginManagement></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><pluginManagement></span></span>
<span class="line"><span style="color:#24292e;"> <!-- NOTE: These plugins will be removed from future versions of the super POM --></span></span>
<span class="line"><span style="color:#24292e;"> <!-- They are kept for the moment as they are very unlikely to conflict with lifecycle mappings (MNG-4453) --></span></span>
<span class="line"><span style="color:#24292e;"></pluginManagement></span></span></code></pre></div><h4 id="父-pom" tabindex="-1">父 POM <a class="header-anchor" href="#父-pom" aria-label="Permalink to "父 POM""></a></h4><p>和 Java 类一样,POM 之间其实也是<strong>单继承</strong>的。如果我们给一个 POM 指定了父 POM,那么继承关系如下图所示:</p><p><img src="/images/image-20220701112032458.png" alt="image-20220701112032458"></p><h4 id="有效-pom" tabindex="-1">有效 POM <a class="header-anchor" href="#有效-pom" aria-label="Permalink to "有效 POM""></a></h4><p>有效 POM 英文翻译为 effective POM,它的概念是这样的——在 POM 的继承关系中,子 POM 可以覆盖父 POM 中的配置;如果子 POM 没有覆盖,那么父 POM 中的配置将会被继承。按照这个规则,继承关系中的所有 POM 叠加到一起,就得到了一个最终生效的 POM。显然 Maven 实际运行过程中,执行构建操作就是按照这个最终生效的 POM 来运行的。这个最终生效的 POM 就是<strong>有效 POM</strong>,英文叫<strong>effective POM</strong></p><p>查看有效 POM:</p><blockquote><p>mvn help:effective-pom</p></blockquote><p>综上所述,平时我们使用和配置的 POM 其实大致是由四个层次组成的:</p><ul><li>超级 POM:所有 POM 默认继承,只是有直接和间接之分。</li><li>父 POM:这一层可能没有,可能有一层,也可能有很多层。</li><li>当前 pom.xml 配置的 POM:我们最多关注和最多使用的一层。</li><li>有效 POM:隐含的一层,但是实际上真正生效的一层。</li></ul><h4 id="pom文件构成" tabindex="-1">Pom文件构成 <a class="header-anchor" href="#pom文件构成" aria-label="Permalink to "Pom文件构成""></a></h4><blockquote><p>一个基本的pom.xml文件配置如下</p></blockquote><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><?xml version="1.0" encoding="UTF-8"?></span></span>
<span class="line"><span style="color:#e1e4e8;"><project xmlns="http://maven.apache.org/POM/4.0.0"</span></span>
<span class="line"><span style="color:#e1e4e8;"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"</span></span>
<span class="line"><span style="color:#e1e4e8;"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"></span></span>
<span class="line"><span style="color:#e1e4e8;"> <!-- maven模型的版本,对于maven2和maven3来说,只能是4.0.0 --></span></span>
<span class="line"><span style="color:#e1e4e8;"> <modelVersion>4.0.0</modelVersion></span></span>
<span class="line"><span style="color:#e1e4e8;"></span></span>
<span class="line"><span style="color:#e1e4e8;"> <!-- 公司或者组织的唯一标志,一般是公司域名的倒写,或者是公司域名倒写+项目名。并且配置时生成的路径也是由此生成, 如com.companyname.project-group,maven会将该项目打成的jar包放本地路径:/com/companyname/project-group --></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>org.heima</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> </span></span>
<span class="line"><span style="color:#e1e4e8;"> <!-- 项目的唯一ID,一个groupId下面可以有多个项目,通过artifactId来区分 --></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>maven_project</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"></span></span>
<span class="line"><span style="color:#e1e4e8;"> <!-- 项目的版本号 --></span></span>
<span class="line"><span style="color:#e1e4e8;"> <version>1.0-SNAPSHOT</version></span></span>
<span class="line"><span style="color:#e1e4e8;"></project></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><?xml version="1.0" encoding="UTF-8"?></span></span>
<span class="line"><span style="color:#24292e;"><project xmlns="http://maven.apache.org/POM/4.0.0"</span></span>
<span class="line"><span style="color:#24292e;"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"</span></span>
<span class="line"><span style="color:#24292e;"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"></span></span>
<span class="line"><span style="color:#24292e;"> <!-- maven模型的版本,对于maven2和maven3来说,只能是4.0.0 --></span></span>
<span class="line"><span style="color:#24292e;"> <modelVersion>4.0.0</modelVersion></span></span>
<span class="line"><span style="color:#24292e;"></span></span>
<span class="line"><span style="color:#24292e;"> <!-- 公司或者组织的唯一标志,一般是公司域名的倒写,或者是公司域名倒写+项目名。并且配置时生成的路径也是由此生成, 如com.companyname.project-group,maven会将该项目打成的jar包放本地路径:/com/companyname/project-group --></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>org.heima</groupId></span></span>
<span class="line"><span style="color:#24292e;"> </span></span>
<span class="line"><span style="color:#24292e;"> <!-- 项目的唯一ID,一个groupId下面可以有多个项目,通过artifactId来区分 --></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>maven_project</artifactId></span></span>
<span class="line"><span style="color:#24292e;"></span></span>
<span class="line"><span style="color:#24292e;"> <!-- 项目的版本号 --></span></span>
<span class="line"><span style="color:#24292e;"> <version>1.0-SNAPSHOT</version></span></span>
<span class="line"><span style="color:#24292e;"></project></span></span></code></pre></div><p>所有 POM 文件都需要 <code><project></code> 标签元素和该标签下的三个必需字段:groupId,artifactId,version。</p><pre><code> groupId + artifactId + version = 坐标,坐标可用于标识互联网中的唯一资源,在Maven中,坐标是Jar包的唯一标识,Maven通过坐标在仓库中找到项目所需的Jar包。
</code></pre><h3 id="常见标签" tabindex="-1">常见标签 <a class="header-anchor" href="#常见标签" aria-label="Permalink to "常见标签""></a></h3><blockquote><p>下面我们看下Maven中的常用标签</p></blockquote><h4 id="parent标签" tabindex="-1">parent标签 <a class="header-anchor" href="#parent标签" aria-label="Permalink to "parent标签""></a></h4><blockquote><p>在maven多模块项目中引用父pom依赖,在<code>springboot</code>项目中就有父依赖</p></blockquote><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><!--引用springBoot父项目--></span></span>
<span class="line"><span style="color:#e1e4e8;"><parent></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>spring-boot-starter-parent</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <version>2.2.2.RELEASE</version></span></span>
<span class="line"><span style="color:#e1e4e8;"></parent></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><!--引用springBoot父项目--></span></span>
<span class="line"><span style="color:#24292e;"><parent></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>spring-boot-starter-parent</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> <version>2.2.2.RELEASE</version></span></span>
<span class="line"><span style="color:#24292e;"></parent></span></span></code></pre></div><h4 id="properties标签" tabindex="-1">properties标签 <a class="header-anchor" href="#properties标签" aria-label="Permalink to "properties标签""></a></h4><blockquote><p>定义一些全局属性值,常用于jar包版本定义全局管理jar包版本后面可以<code>${}</code> 取值</p></blockquote><pre><code> 在springboot项目中父pom会定义一些项目jar包版本依赖 ,所以我们在引用jar时候才不用写jar包版本,会自动跟随父pom中定义的jar包版本
</code></pre><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><parent></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>spring-boot-dependencies</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <version>2.4.7</version></span></span>
<span class="line"><span style="color:#e1e4e8;"></parent></span></span>
<span class="line"><span style="color:#e1e4e8;"></span></span>
<span class="line"><span style="color:#e1e4e8;"><properties></span></span>
<span class="line"><span style="color:#e1e4e8;"> <activemq.version>5.15.11</activemq.version></span></span>
<span class="line"><span style="color:#e1e4e8;"> <antlr2.version>2.7.7</antlr2.version></span></span>
<span class="line"><span style="color:#e1e4e8;"> <appengine-sdk.version>1.9.77</appengine-sdk.version></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artemis.version>2.10.1</artemis.version></span></span>
<span class="line"><span style="color:#e1e4e8;"> <aspectj.version>1.9.5</aspectj.version></span></span>
<span class="line"><span style="color:#e1e4e8;"> <assertj.version>3.13.2</assertj.version></span></span>
<span class="line"><span style="color:#e1e4e8;"> <atomikos.version>4.0.6</atomikos.version></span></span>
<span class="line"><span style="color:#e1e4e8;"> <awaitility.version>4.0.1</awaitility.version></span></span>
<span class="line"><span style="color:#e1e4e8;"> <bitronix.version>2.1.4</bitronix.version></span></span>
<span class="line"><span style="color:#e1e4e8;"> <build-helper-maven-plugin.version>3.0.0</build-helper-maven-plugin.version></span></span>
<span class="line"><span style="color:#e1e4e8;"> <byte-buddy.version>1.10.4</byte-buddy.version></span></span>
<span class="line"><span style="color:#e1e4e8;"> <caffeine.version>2.8.0</caffeine.version></span></span>
<span class="line"><span style="color:#e1e4e8;"> <cassandra-driver.version>3.7.2</cassandra-driver.version></span></span>
<span class="line"><span style="color:#e1e4e8;"> <classmate.version>1.5.1</classmate.version></span></span>
<span class="line"><span style="color:#e1e4e8;"> <commons-codec.version>1.13</commons-codec.version></span></span>
<span class="line"><span style="color:#e1e4e8;"> </properties></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><parent></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>spring-boot-dependencies</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> <version>2.4.7</version></span></span>
<span class="line"><span style="color:#24292e;"></parent></span></span>
<span class="line"><span style="color:#24292e;"></span></span>
<span class="line"><span style="color:#24292e;"><properties></span></span>
<span class="line"><span style="color:#24292e;"> <activemq.version>5.15.11</activemq.version></span></span>
<span class="line"><span style="color:#24292e;"> <antlr2.version>2.7.7</antlr2.version></span></span>
<span class="line"><span style="color:#24292e;"> <appengine-sdk.version>1.9.77</appengine-sdk.version></span></span>
<span class="line"><span style="color:#24292e;"> <artemis.version>2.10.1</artemis.version></span></span>
<span class="line"><span style="color:#24292e;"> <aspectj.version>1.9.5</aspectj.version></span></span>
<span class="line"><span style="color:#24292e;"> <assertj.version>3.13.2</assertj.version></span></span>
<span class="line"><span style="color:#24292e;"> <atomikos.version>4.0.6</atomikos.version></span></span>
<span class="line"><span style="color:#24292e;"> <awaitility.version>4.0.1</awaitility.version></span></span>
<span class="line"><span style="color:#24292e;"> <bitronix.version>2.1.4</bitronix.version></span></span>
<span class="line"><span style="color:#24292e;"> <build-helper-maven-plugin.version>3.0.0</build-helper-maven-plugin.version></span></span>
<span class="line"><span style="color:#24292e;"> <byte-buddy.version>1.10.4</byte-buddy.version></span></span>
<span class="line"><span style="color:#24292e;"> <caffeine.version>2.8.0</caffeine.version></span></span>
<span class="line"><span style="color:#24292e;"> <cassandra-driver.version>3.7.2</cassandra-driver.version></span></span>
<span class="line"><span style="color:#24292e;"> <classmate.version>1.5.1</classmate.version></span></span>
<span class="line"><span style="color:#24292e;"> <commons-codec.version>1.13</commons-codec.version></span></span>
<span class="line"><span style="color:#24292e;"> </properties></span></span></code></pre></div><h4 id="dependencymanagement标签" tabindex="-1">dependencyManagement标签 <a class="header-anchor" href="#dependencymanagement标签" aria-label="Permalink to "dependencyManagement标签""></a></h4><blockquote><p>在<code>Maven</code>多模块的时候,管理依赖关系是非常重要的,各种依赖包冲突,查询问题起来非常复杂,于是就用到了,在springboot项目中父模块就定义了</p></blockquote><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><dependencyManagement></span></span>
<span class="line"><span style="color:#e1e4e8;"> <dependencies></span></span>
<span class="line"><span style="color:#e1e4e8;"> <dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>spring-boot</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <version>2.2.2.RELEASE</version></span></span>
<span class="line"><span style="color:#e1e4e8;"> </dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> <dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>spring-boot-test</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <version>2.2.2.RELEASE</version></span></span>
<span class="line"><span style="color:#e1e4e8;"> </dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> <dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>spring-boot-test-autoconfigure</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <version>2.2.2.RELEASE</version></span></span>
<span class="line"><span style="color:#e1e4e8;"> </dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> </dependencyManagement></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><dependencyManagement></span></span>
<span class="line"><span style="color:#24292e;"> <dependencies></span></span>
<span class="line"><span style="color:#24292e;"> <dependency></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>spring-boot</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> <version>2.2.2.RELEASE</version></span></span>
<span class="line"><span style="color:#24292e;"> </dependency></span></span>
<span class="line"><span style="color:#24292e;"> <dependency></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>spring-boot-test</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> <version>2.2.2.RELEASE</version></span></span>
<span class="line"><span style="color:#24292e;"> </dependency></span></span>
<span class="line"><span style="color:#24292e;"> <dependency></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>spring-boot-test-autoconfigure</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> <version>2.2.2.RELEASE</version></span></span>
<span class="line"><span style="color:#24292e;"> </dependency></span></span>
<span class="line"><span style="color:#24292e;"> </dependencyManagement></span></span></code></pre></div><blockquote><p>那么在子模块中只需要<code><groupId>和<artifactId></code>即可,不需要加入版本号,</p></blockquote><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>spring-boot-starter-aop</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"></dependency></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><dependency></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>spring-boot-starter-aop</artifactId></span></span>
<span class="line"><span style="color:#24292e;"></dependency></span></span></code></pre></div><blockquote><p>使用dependencyManagement可以统一管理项目的版本号,确保应用的各个项目的依赖和版本一致,不用每个模块项目都弄一个版本号,不利于管理,当需要变更版本号的时候只需要在父类容器里更新,不需要任何一个子项目的修改;如果某个子项目需要另外一个特殊的版本号时,只需要在自己的模块dependencies中声明一个版本号即可。子类就会使用子类声明的版本号,不继承于父类版本号</p></blockquote><h4 id="dependencies标签" tabindex="-1">dependencies标签 <a class="header-anchor" href="#dependencies标签" aria-label="Permalink to "dependencies标签""></a></h4><blockquote><p>用于引入项目依赖</p></blockquote><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><dependencies></span></span>
<span class="line"><span style="color:#e1e4e8;"> <!--aop 切面--></span></span>
<span class="line"><span style="color:#e1e4e8;"> <dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>spring-boot-starter-aop</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> </dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"></dependencies></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><dependencies></span></span>
<span class="line"><span style="color:#24292e;"> <!--aop 切面--></span></span>
<span class="line"><span style="color:#24292e;"> <dependency></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>spring-boot-starter-aop</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> </dependency></span></span>
<span class="line"><span style="color:#24292e;"></dependencies></span></span></code></pre></div><h5 id="dependencies和dependencymanagement区别" tabindex="-1">dependencies和dependencyManagement区别 <a class="header-anchor" href="#dependencies和dependencymanagement区别" aria-label="Permalink to "dependencies和dependencyManagement区别""></a></h5><p><code>Dependencies</code>相对于<code>dependencyManagement</code>,所有声明在dependencies里的依赖都会自动引入,并默认被所有的子项目继承, 而<code>dependencyManagement</code>里只是声明依赖,并不自动实现引入,因此子项目需要显示的声明需要用的依赖。</p><pre><code> 如果不在子项目中声明依赖,是不会从父项目中继承下来的;只有在子项目中写了该依赖项,并且没有指定具体版本,才会从父项目中继承该项,并且version和scope都读取自父pom;另外如果子项目中指定了版本号,那么会使用子项目中指定的jar版本。
</code></pre><h4 id="build标签" tabindex="-1">build标签 <a class="header-anchor" href="#build标签" aria-label="Permalink to "build标签""></a></h4><p>在实际使用 Maven 的过程中,我们会发现 build 标签有时候有,有时候没,这是怎么回事呢?其实通过有效 POM 我们能够看到,build 标签的相关配置其实一直都在,只是在我们需要定制构建过程的时候才会通过配置 build 标签覆盖默认值或补充配置。这一点我们可以通过打印有效 POM 来看到。</p><p>所以<strong>本质</strong>上来说:我们配置的 build 标签都是对<strong>超级 POM 配置</strong>的<strong>叠加</strong>。那我们又为什么要在默认配置的基础上叠加呢?很简单,在默认配置无法满足需求的时候<strong>定制构建过程</strong>。</p><p><strong>build 标签组成</strong></p><p>从示例中我们能够看到,build 标签的子标签大致包含三个主体部分:</p><p><strong>① 定义约定的目录结构</strong></p><p>参考示例中的如下部分:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><directory>${project.basedir}/target</directory></span></span>
<span class="line"><span style="color:#e1e4e8;"> <outputDirectory>${project.build.directory}/classes</outputDirectory></span></span>
<span class="line"><span style="color:#e1e4e8;"> <finalName>${project.artifactId}-${project.version}</finalName></span></span>
<span class="line"><span style="color:#e1e4e8;"> <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory></span></span>
<span class="line"><span style="color:#e1e4e8;"> <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory></span></span>
<span class="line"><span style="color:#e1e4e8;"> <scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory></span></span>
<span class="line"><span style="color:#e1e4e8;"> <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory></span></span>
<span class="line"><span style="color:#e1e4e8;"> <resources></span></span>
<span class="line"><span style="color:#e1e4e8;"> <resource></span></span>
<span class="line"><span style="color:#e1e4e8;"> <directory>${project.basedir}/src/main/resources</directory></span></span>
<span class="line"><span style="color:#e1e4e8;"> </resource></span></span>
<span class="line"><span style="color:#e1e4e8;"> </resources></span></span>
<span class="line"><span style="color:#e1e4e8;"> <testResources></span></span>
<span class="line"><span style="color:#e1e4e8;"> <testResource></span></span>
<span class="line"><span style="color:#e1e4e8;"> <directory>${project.basedir}/src/test/resources</directory></span></span>
<span class="line"><span style="color:#e1e4e8;"> </testResource></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><directory>${project.basedir}/target</directory></span></span>
<span class="line"><span style="color:#24292e;"> <outputDirectory>${project.build.directory}/classes</outputDirectory></span></span>
<span class="line"><span style="color:#24292e;"> <finalName>${project.artifactId}-${project.version}</finalName></span></span>
<span class="line"><span style="color:#24292e;"> <testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory></span></span>
<span class="line"><span style="color:#24292e;"> <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory></span></span>
<span class="line"><span style="color:#24292e;"> <scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory></span></span>
<span class="line"><span style="color:#24292e;"> <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory></span></span>
<span class="line"><span style="color:#24292e;"> <resources></span></span>
<span class="line"><span style="color:#24292e;"> <resource></span></span>
<span class="line"><span style="color:#24292e;"> <directory>${project.basedir}/src/main/resources</directory></span></span>
<span class="line"><span style="color:#24292e;"> </resource></span></span>
<span class="line"><span style="color:#24292e;"> </resources></span></span>
<span class="line"><span style="color:#24292e;"> <testResources></span></span>
<span class="line"><span style="color:#24292e;"> <testResource></span></span>
<span class="line"><span style="color:#24292e;"> <directory>${project.basedir}/src/test/resources</directory></span></span>
<span class="line"><span style="color:#24292e;"> </testResource></span></span></code></pre></div><p>我们能看到各个目录的作用如下:</p><table><thead><tr><th>目录名</th><th>作用</th></tr></thead><tbody><tr><td>sourceDirectory</td><td>主体源程序存放目录</td></tr><tr><td>scriptSourceDirectory</td><td>脚本源程序存放目录</td></tr><tr><td>testSourceDirectory</td><td>测试源程序存放目录</td></tr><tr><td>outputDirectory</td><td>主体源程序编译结果输出目录</td></tr><tr><td>testOutputDirectory</td><td>测试源程序编译结果输出目录</td></tr><tr><td>resources</td><td>主体资源文件存放目录</td></tr><tr><td>testResources</td><td>测试资源文件存放目录</td></tr><tr><td>directory</td><td>构建结果输出目录</td></tr></tbody></table><p><strong>② 备用插件管理</strong></p><p>pluginManagement 标签存放着几个插件:</p><ul><li>maven-antrun-plugin</li><li>maven-assembly-plugin</li><li>maven-dependency-plugin</li><li>maven-release-plugin</li></ul><p>通过 pluginManagement 标签管理起来的插件就像 dependencyManagement 一样,子工程使用时可以省略版本号,起到在父工程中统一管理版本的效果。情看下面例子:</p><ul><li>被 spring-boot-dependencies 管理的插件信息:</li><li>子工程使用的插件信息:</li></ul><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><build></span></span>
<span class="line"><span style="color:#e1e4e8;"> <plugins></span></span>
<span class="line"><span style="color:#e1e4e8;"> <plugin></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>spring-boot-maven-plugin</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> </plugin></span></span>
<span class="line"><span style="color:#e1e4e8;"> </plugins></span></span>
<span class="line"><span style="color:#e1e4e8;"></build></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><build></span></span>
<span class="line"><span style="color:#24292e;"> <plugins></span></span>
<span class="line"><span style="color:#24292e;"> <plugin></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>spring-boot-maven-plugin</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> </plugin></span></span>
<span class="line"><span style="color:#24292e;"> </plugins></span></span>
<span class="line"><span style="color:#24292e;"></build></span></span></code></pre></div><p><strong>③生命周期插件</strong></p><p>plugins 标签存放的是默认生命周期中实际会用到的插件,这些插件想必大家都不陌生,所以抛开插件本身不谈,我们来看看 plugin 标签的结构:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><plugin></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>maven-compiler-plugin</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <version>3.1</version></span></span>
<span class="line"><span style="color:#e1e4e8;"> <executions></span></span>
<span class="line"><span style="color:#e1e4e8;"> <execution></span></span>
<span class="line"><span style="color:#e1e4e8;"> <id>default-compile</id></span></span>
<span class="line"><span style="color:#e1e4e8;"> <phase>compile</phase></span></span>
<span class="line"><span style="color:#e1e4e8;"> <goals></span></span>
<span class="line"><span style="color:#e1e4e8;"> <goal>compile</goal></span></span>
<span class="line"><span style="color:#e1e4e8;"> </goals></span></span>
<span class="line"><span style="color:#e1e4e8;"> </execution></span></span>
<span class="line"><span style="color:#e1e4e8;"> <execution></span></span>
<span class="line"><span style="color:#e1e4e8;"> <id>default-testCompile</id></span></span>
<span class="line"><span style="color:#e1e4e8;"> <phase>test-compile</phase></span></span>
<span class="line"><span style="color:#e1e4e8;"> <goals></span></span>
<span class="line"><span style="color:#e1e4e8;"> <goal>testCompile</goal></span></span>
<span class="line"><span style="color:#e1e4e8;"> </goals></span></span>
<span class="line"><span style="color:#e1e4e8;"> </execution></span></span>
<span class="line"><span style="color:#e1e4e8;"> </executions></span></span>
<span class="line"><span style="color:#e1e4e8;"></plugin></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><plugin></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>maven-compiler-plugin</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> <version>3.1</version></span></span>
<span class="line"><span style="color:#24292e;"> <executions></span></span>
<span class="line"><span style="color:#24292e;"> <execution></span></span>
<span class="line"><span style="color:#24292e;"> <id>default-compile</id></span></span>
<span class="line"><span style="color:#24292e;"> <phase>compile</phase></span></span>
<span class="line"><span style="color:#24292e;"> <goals></span></span>
<span class="line"><span style="color:#24292e;"> <goal>compile</goal></span></span>
<span class="line"><span style="color:#24292e;"> </goals></span></span>
<span class="line"><span style="color:#24292e;"> </execution></span></span>
<span class="line"><span style="color:#24292e;"> <execution></span></span>
<span class="line"><span style="color:#24292e;"> <id>default-testCompile</id></span></span>
<span class="line"><span style="color:#24292e;"> <phase>test-compile</phase></span></span>
<span class="line"><span style="color:#24292e;"> <goals></span></span>
<span class="line"><span style="color:#24292e;"> <goal>testCompile</goal></span></span>
<span class="line"><span style="color:#24292e;"> </goals></span></span>
<span class="line"><span style="color:#24292e;"> </execution></span></span>
<span class="line"><span style="color:#24292e;"> </executions></span></span>
<span class="line"><span style="color:#24292e;"></plugin></span></span></code></pre></div><p><strong>典型应用:指定 JDK 版本</strong></p><p>① 提出问题</p><p>前面我们在 settings.xml 中配置了 JDK 版本,那么将来把 Maven 工程部署都服务器上,脱离了 settings.xml 配置,如何保证程序正常运行呢?思路就是我们直接把 JDK 版本信息告诉负责编译操作的 maven-compiler-plugin 插件,让它在构建过程中,按照我们指定的信息工作。</p><p>② 暂时取消 settings.xml 配置</p><p>为了测试对 maven-compiler-plugin 插件进行配置的效果,我们暂时取消 settings.xml 中的 profile 配置。</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><!-- 配置Maven工程的默认JDK版本 --></span></span>
<span class="line"><span style="color:#e1e4e8;"><!-- <profile></span></span>
<span class="line"><span style="color:#e1e4e8;"> <id>jdk-1.8</id></span></span>
<span class="line"><span style="color:#e1e4e8;"> <activation></span></span>
<span class="line"><span style="color:#e1e4e8;"> <activeByDefault>true</activeByDefault></span></span>
<span class="line"><span style="color:#e1e4e8;"> <jdk>1.8</jdk></span></span>
<span class="line"><span style="color:#e1e4e8;"> </activation></span></span>
<span class="line"><span style="color:#e1e4e8;"> <properties></span></span>
<span class="line"><span style="color:#e1e4e8;"> <maven.compiler.source>1.8</maven.compiler.source></span></span>
<span class="line"><span style="color:#e1e4e8;"> <maven.compiler.target>1.8</maven.compiler.target></span></span>
<span class="line"><span style="color:#e1e4e8;"> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion></span></span>
<span class="line"><span style="color:#e1e4e8;"> </properties></span></span>
<span class="line"><span style="color:#e1e4e8;"></profile> --></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><!-- 配置Maven工程的默认JDK版本 --></span></span>
<span class="line"><span style="color:#24292e;"><!-- <profile></span></span>
<span class="line"><span style="color:#24292e;"> <id>jdk-1.8</id></span></span>
<span class="line"><span style="color:#24292e;"> <activation></span></span>
<span class="line"><span style="color:#24292e;"> <activeByDefault>true</activeByDefault></span></span>
<span class="line"><span style="color:#24292e;"> <jdk>1.8</jdk></span></span>
<span class="line"><span style="color:#24292e;"> </activation></span></span>
<span class="line"><span style="color:#24292e;"> <properties></span></span>
<span class="line"><span style="color:#24292e;"> <maven.compiler.source>1.8</maven.compiler.source></span></span>
<span class="line"><span style="color:#24292e;"> <maven.compiler.target>1.8</maven.compiler.target></span></span>
<span class="line"><span style="color:#24292e;"> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion></span></span>
<span class="line"><span style="color:#24292e;"> </properties></span></span>
<span class="line"><span style="color:#24292e;"></profile> --></span></span></code></pre></div><p>③ 编写源文件代码</p><p>很明显这里用到了 Lambda 表达式,这是 JDK 1.8 才支持的语法。</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;">package com.itheima.maven;</span></span>
<span class="line"><span style="color:#e1e4e8;"></span></span>
<span class="line"><span style="color:#e1e4e8;">public class Hello {</span></span>
<span class="line"><span style="color:#e1e4e8;"></span></span>
<span class="line"><span style="color:#e1e4e8;"> public void hello() {</span></span>
<span class="line"><span style="color:#e1e4e8;"> new Thread(()->{</span></span>
<span class="line"><span style="color:#e1e4e8;"> System.out.println("thread ...");</span></span>
<span class="line"><span style="color:#e1e4e8;"> }).start();</span></span>
<span class="line"><span style="color:#e1e4e8;"> }</span></span>
<span class="line"><span style="color:#e1e4e8;"></span></span>
<span class="line"><span style="color:#e1e4e8;">}</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;">package com.itheima.maven;</span></span>
<span class="line"><span style="color:#24292e;"></span></span>
<span class="line"><span style="color:#24292e;">public class Hello {</span></span>
<span class="line"><span style="color:#24292e;"></span></span>
<span class="line"><span style="color:#24292e;"> public void hello() {</span></span>
<span class="line"><span style="color:#24292e;"> new Thread(()->{</span></span>
<span class="line"><span style="color:#24292e;"> System.out.println("thread ...");</span></span>
<span class="line"><span style="color:#24292e;"> }).start();</span></span>
<span class="line"><span style="color:#24292e;"> }</span></span>
<span class="line"><span style="color:#24292e;"></span></span>
<span class="line"><span style="color:#24292e;">}</span></span></code></pre></div><p>此时我们执行编译命令:</p><p><img src="/images/image-20220701160437052.png" alt="image-20220701160437052"></p><p>④ 配置构建过程</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><!-- build 标签:意思是告诉 Maven,你的构建行为,我要开始定制了! --></span></span>
<span class="line"><span style="color:#e1e4e8;"><build></span></span>
<span class="line"><span style="color:#e1e4e8;"> <!-- plugins 标签:Maven 你给我听好了,你给我构建的时候要用到这些插件! --></span></span>
<span class="line"><span style="color:#e1e4e8;"> <plugins></span></span>
<span class="line"><span style="color:#e1e4e8;"> <!-- plugin 标签:这是我要指定的一个具体的插件 --></span></span>
<span class="line"><span style="color:#e1e4e8;"> <plugin></span></span>
<span class="line"><span style="color:#e1e4e8;"> <!-- 插件的坐标。此处引用的 maven-compiler-plugin 插件不是第三方的,是一个 Maven 自带的插件。 --></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>org.apache.maven.plugins</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>maven-compiler-plugin</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <version>3.1</version></span></span>
<span class="line"><span style="color:#e1e4e8;"> </span></span>
<span class="line"><span style="color:#e1e4e8;"> <!-- configuration 标签:配置 maven-compiler-plugin 插件 --></span></span>
<span class="line"><span style="color:#e1e4e8;"> <configuration></span></span>
<span class="line"><span style="color:#e1e4e8;"> <!-- 具体配置信息会因为插件不同、需求不同而有所差异 --></span></span>
<span class="line"><span style="color:#e1e4e8;"> <source>1.8</source></span></span>
<span class="line"><span style="color:#e1e4e8;"> <target>1.8</target></span></span>
<span class="line"><span style="color:#e1e4e8;"> <encoding>UTF-8</encoding></span></span>
<span class="line"><span style="color:#e1e4e8;"> </configuration></span></span>
<span class="line"><span style="color:#e1e4e8;"> </plugin></span></span>
<span class="line"><span style="color:#e1e4e8;"> </plugins></span></span>
<span class="line"><span style="color:#e1e4e8;"></build></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><!-- build 标签:意思是告诉 Maven,你的构建行为,我要开始定制了! --></span></span>
<span class="line"><span style="color:#24292e;"><build></span></span>
<span class="line"><span style="color:#24292e;"> <!-- plugins 标签:Maven 你给我听好了,你给我构建的时候要用到这些插件! --></span></span>
<span class="line"><span style="color:#24292e;"> <plugins></span></span>
<span class="line"><span style="color:#24292e;"> <!-- plugin 标签:这是我要指定的一个具体的插件 --></span></span>
<span class="line"><span style="color:#24292e;"> <plugin></span></span>
<span class="line"><span style="color:#24292e;"> <!-- 插件的坐标。此处引用的 maven-compiler-plugin 插件不是第三方的,是一个 Maven 自带的插件。 --></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>org.apache.maven.plugins</groupId></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>maven-compiler-plugin</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> <version>3.1</version></span></span>
<span class="line"><span style="color:#24292e;"> </span></span>
<span class="line"><span style="color:#24292e;"> <!-- configuration 标签:配置 maven-compiler-plugin 插件 --></span></span>
<span class="line"><span style="color:#24292e;"> <configuration></span></span>
<span class="line"><span style="color:#24292e;"> <!-- 具体配置信息会因为插件不同、需求不同而有所差异 --></span></span>
<span class="line"><span style="color:#24292e;"> <source>1.8</source></span></span>
<span class="line"><span style="color:#24292e;"> <target>1.8</target></span></span>
<span class="line"><span style="color:#24292e;"> <encoding>UTF-8</encoding></span></span>
<span class="line"><span style="color:#24292e;"> </configuration></span></span>
<span class="line"><span style="color:#24292e;"> </plugin></span></span>
<span class="line"><span style="color:#24292e;"> </plugins></span></span>
<span class="line"><span style="color:#24292e;"></build></span></span></code></pre></div><p>⑤ 再次执行编译命令</p><p><img src="/images/image-20220701160517183.png" alt="image-20220701160517183"></p><p>⑥ 两种配置方式比较</p><ul><li>settings.xml 中配置:仅在本地生效,如果脱离当前 settings.xml 能够覆盖的范围,则无法生效。</li><li>在当前 Maven 工程 pom.xml 中配置:无论在哪个环境执行编译等构建操作都有效。</li></ul><p>还有另外一种方式</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><properties></span></span>
<span class="line"><span style="color:#e1e4e8;"> <maven.compiler.source>1.8</maven.compiler.source></span></span>
<span class="line"><span style="color:#e1e4e8;"> <maven.compiler.target>1.8</maven.compiler.target></span></span>
<span class="line"><span style="color:#e1e4e8;"> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></span></span>
<span class="line"><span style="color:#e1e4e8;"></properties></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><properties></span></span>
<span class="line"><span style="color:#24292e;"> <maven.compiler.source>1.8</maven.compiler.source></span></span>
<span class="line"><span style="color:#24292e;"> <maven.compiler.target>1.8</maven.compiler.target></span></span>
<span class="line"><span style="color:#24292e;"> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></span></span>
<span class="line"><span style="color:#24292e;"></properties></span></span></code></pre></div><h2 id="依赖管理" tabindex="-1">依赖管理 <a class="header-anchor" href="#依赖管理" aria-label="Permalink to "依赖管理""></a></h2><h3 id="依赖传递" tabindex="-1">依赖传递 <a class="header-anchor" href="#依赖传递" aria-label="Permalink to "依赖传递""></a></h3><p><img src="/images/image-20230917172544222.png" alt="image-20230917172544222"></p><h3 id="传递性依赖机制" tabindex="-1">传递性依赖机制 <a class="header-anchor" href="#传递性依赖机制" aria-label="Permalink to "传递性依赖机制""></a></h3><pre><code> 项目A中,我们为了实现某一个功能通常会引入第三方库,这里是一个compile依赖范围的B依赖,而B依赖同时又依赖于另一个compile依赖范围的C组件。
那么对A而言,C就是它的一个传递性依赖,在Maven中,其会将我们在POM文件中显式声明的直接依赖(本例的B依赖)引入到项目中,对于**必要**的间接依赖(本例的C依赖)则会以传递性依赖的形式**自动地**引入到项目A中,而无需我们手动显式地在POM文件中声明C依赖来引入。
Maven的传递性依赖机制,大大地减少了人工维护间接依赖的复杂度
</code></pre><h4 id="传递性依赖的依赖范围" tabindex="-1">传递性依赖的依赖范围 <a class="header-anchor" href="#传递性依赖的依赖范围" aria-label="Permalink to "传递性依赖的依赖范围""></a></h4><blockquote><p>项目A依赖于B组件,B组件依赖于C组件,则我们将A对于B的依赖称之为<strong>第一直接依赖</strong>,B对于C的依赖称之为<strong>第二直接依赖</strong>。</p></blockquote><pre><code> 根据上文可知,A对于C的依赖是传递性依赖,**必要**的间接依赖C将通过传递性依赖机制,被自动引入到A中。那么如何判定一个间接依赖是否有必要被引入呢?间接依赖被引入后其依赖范围又是什么呢?
答案其实很简单,就是通过第一直接依赖的依赖范围和第二直接依赖的依赖范围之间的关系,来判定是否有必要引入间接依赖以及确定引入间接依赖后其依赖范围。
如下表所示,若结果为N,则意味着该传递性依赖为非必要的,无需引入;否则,该间接依赖为必要的并自动引入该间接依赖,且引入后该传递依赖的依赖范围如下表单元格中的文字所示
</code></pre><blockquote><p>Maven依赖范围不仅控制依赖与classpath的关系,还会影响依赖传递</p></blockquote><pre><code> 最左边一列表示第一直接依赖范围,最上面一行表示第二直接依赖范围,中间的交叉单元格则表示传递性依赖范围
</code></pre><table><thead><tr><th></th><th>compile</th><th>test</th><th>provided</th><th>runtime</th></tr></thead><tbody><tr><td>compile</td><td>compile</td><td>N</td><td>N</td><td>runtime</td></tr><tr><td>test</td><td>test</td><td>N</td><td>N</td><td>test</td></tr><tr><td>provided</td><td>provided</td><td>N</td><td>provided</td><td>provided</td></tr><tr><td>runtime</td><td>runtime</td><td>N</td><td>N</td><td>runtime</td></tr></tbody></table><blockquote><p>仔细观察上面表格,我们发现这样的规律</p></blockquote><ul><li>当第二直接依赖的范围是compile的时候,传递性依赖的范围与第一直接依赖的范围一致;</li><li>当第二直接依赖的范围是test的时候,依赖不会得以传递;</li><li>当第二直接依赖的范围是provided的时候,只传递第一直接依赖的范围也为provided的依赖,切传递性依赖的范围同样为provided;</li><li>当第二直接依赖的范围是runtime的时候,传递性依赖的范围与第一直接依赖的范围一致,但compile例外,此时传递性依赖的范围为runtime。</li></ul><h4 id="依赖调解" tabindex="-1">依赖调解 <a class="header-anchor" href="#依赖调解" aria-label="Permalink to "依赖调解""></a></h4><blockquote><p>在Maven中由于传递性依赖的机制,一般情况下我们不需要关心间接依赖的管理。</p></blockquote><pre><code> 而当间接依赖出问题时,我们需要知道该间接依赖是通过哪条依赖路径引入的,特别是该间接依赖存在多条引入路径时,确定间接依赖引入的路径就显得尤为重要。当一个间接依赖存在多条引入路径时,为避免依赖重复Maven会通过**依赖调解**来确定该间接依赖的引入路径
</code></pre><blockquote><p>依赖调解遵循以下原则,<strong>优先使用第一原则,当第一原则无法解决时,则通过第二原则解决</strong></p></blockquote><ul><li>第一原则: 路径最短者优先</li><li>第二原则: 第一声明者优先</li></ul><h5 id="路径最短者优先" tabindex="-1">路径最短者优先 <a class="header-anchor" href="#路径最短者优先" aria-label="Permalink to "路径最短者优先""></a></h5><blockquote><p>假设在项目A中存在如下依赖关系:</p></blockquote><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;">A -> X -> Y -> Z(2.0) // dist(A->Z) = 3</span></span>
<span class="line"><span style="color:#e1e4e8;">A -> M -> Z(2.1) // dist(A->Z) = 2</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;">A -> X -> Y -> Z(2.0) // dist(A->Z) = 3</span></span>
<span class="line"><span style="color:#24292e;">A -> M -> Z(2.1) // dist(A->Z) = 2</span></span></code></pre></div><pre><code> 项目A依赖的Z组件有2个版本,很显然不可能同时引入两个版本的间接依赖,这里可以看到,Z(2.0)依赖的依赖路径长度为3,Z(2.1)依赖的依赖路径长度为2。
根据依赖调解的第一原则——**路径最短者优先**,所以,2.1版本的Z组件将通过 A -> M -> Z(2.1) 路径被引入到A中
</code></pre><h5 id="第一声明者优先" tabindex="-1">第一声明者优先 <a class="header-anchor" href="#第一声明者优先" aria-label="Permalink to "第一声明者优先""></a></h5><pre><code> 假设在项目B中存在如下依赖关系,间接依赖W在两条依赖路径中的路径长度均为2,这时候就无法通过依赖调解的第一原则来确定引入路径。此时需要使用依赖调解的第二原则——**第一声明者优先**。
根据项目B的POM文件中直接依赖K、P的声明顺序,先声明的直接依赖,则其间接依赖即通过该路径被引入
</code></pre><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;">B -> K -> W(1.0) // dist(B->W) = 2</span></span>
<span class="line"><span style="color:#e1e4e8;">B -> P -> W(2.0) // dist(B->W) = 2</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;">B -> K -> W(1.0) // dist(B->W) = 2</span></span>
<span class="line"><span style="color:#24292e;">B -> P -> W(2.0) // dist(B->W) = 2</span></span></code></pre></div><pre><code> 项目B的POM文件内容如下所示,由于P依赖比K依赖先声明,则2.0版本的的W组件将通过 B -> P -> W(2.0) 路径被引入到B中
</code></pre><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><dependencies></span></span>
<span class="line"><span style="color:#e1e4e8;"> <dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>P</artifactId> </span></span>
<span class="line"><span style="color:#e1e4e8;"> </dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> <dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>K</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> </dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"></dependencies></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><dependencies></span></span>
<span class="line"><span style="color:#24292e;"> <dependency></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>P</artifactId> </span></span>
<span class="line"><span style="color:#24292e;"> </dependency></span></span>
<span class="line"><span style="color:#24292e;"> <dependency></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>K</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> </dependency></span></span>
<span class="line"><span style="color:#24292e;"></dependencies></span></span></code></pre></div><h4 id="依赖处理" tabindex="-1">依赖处理 <a class="header-anchor" href="#依赖处理" aria-label="Permalink to "依赖处理""></a></h4><blockquote><p>有时候依赖调解会引入一些不需要的jar,我们可以通过一些方式进行处理</p></blockquote><h5 id="可选依赖-option" tabindex="-1">可选依赖 option <a class="header-anchor" href="#可选依赖-option" aria-label="Permalink to "可选依赖 option""></a></h5><blockquote><p>可选依赖是通过项目中的POM文件的依赖元素dependency下的option元素中进行配置,只有显式地配置项目中某依赖的option元素为true时,该依赖才是可选依赖;</p></blockquote><pre><code> 不设置该元素或值为false时,该依赖即不是可选依赖,其意义在于,当某个间接依赖是可选依赖时,无论依赖范围是什么,其都不会因为传递性依赖机制而被引入
</code></pre><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>junit</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>junit</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <version>4.13.2</version></span></span>
<span class="line"><span style="color:#e1e4e8;"> <optional>true</optional></span></span>
<span class="line"><span style="color:#e1e4e8;"></dependency></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><dependency></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>junit</groupId></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>junit</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> <version>4.13.2</version></span></span>
<span class="line"><span style="color:#24292e;"> <optional>true</optional></span></span>
<span class="line"><span style="color:#24292e;"></dependency></span></span></code></pre></div><p><strong>optional元素默认值(false)</strong> 当父项目添加junit依赖时,并未添加optional选项,也就是默认的optional元素的值为false。 父项目并未设置optional元素为true,那么便具有依赖传递性。此时,子项目B中会直接引入父项目A中引入的Junit的jar包。也就是说B项目打包时,jar/war包中会包含junit的jar包。</p><p><strong>optional元素为true</strong> 当父项目引入junit依赖时,设置optional元素为true。那么,子项目B便有了更多的选择。</p><p>如果项目B不需要Junit的jar包,那么在其pom文件中不需进行任何处理便可以。如果B项目也需要对应的jar包依赖,可以有两种选择:第一、A项目中对应依赖的optional设置为false或去掉;第二、B项目中直接引入需要的该依赖。</p><h6 id="应用场景" tabindex="-1">应用场景 <a class="header-anchor" href="#应用场景" aria-label="Permalink to "应用场景""></a></h6><blockquote><p>这里简单介绍下option元素的实际应用场景</p></blockquote><pre><code> 我们在开发项目A的过程中,需要依赖一个第三方持久层的M组件,而这个M组件对两种不同数据库均支持( MySql、Oracle),故M组件中需要依赖这两种不同数据库的驱动实现——X、Y组件。
对于开发项目A的工程师而言,他可能在项目开发只需要使用其中一种数据库(例如MySql,其驱动实现为X依赖),如果数据库驱动实现X、Y不是可选依赖,则均会传递到项目A中。
虽然一般情况下这不会引发任何问题,但是会因引入不必要的依赖Y而造成项目体积增大,如果该M组件还支持更多类型的数据库,就会引入更多的不必要的数据库驱动实现依赖进来;而如果M组件中的X、Y依赖是可选依赖的话,则工程师就可以根据实际需要在A项目的POM文件中显式地引入所需数据库的驱动实现依赖即可
</code></pre><h6 id="使用建议" tabindex="-1">使用建议 <a class="header-anchor" href="#使用建议" aria-label="Permalink to "使用建议""></a></h6><blockquote><p>当然,一般情况下是不推荐使用可选依赖的,使用可选依赖一般是因为项目中支持、实现多种特性所造成的</p></blockquote><h5 id="排除依赖-exclusions" tabindex="-1">排除依赖 exclusions <a class="header-anchor" href="#排除依赖-exclusions" aria-label="Permalink to "排除依赖 exclusions""></a></h5><pre><code> 间接依赖是可以通过传递性依赖机制引入到当前项目中,而有时候第三方组件B的C依赖由于版本(1.0)过低存在安全漏洞。
我们期望能够将该间接依赖直接剔除出去,不通过传递依赖的形式引入到项目中,这时即可通过exclusions元素实现,该元素下可以包含若干个 exclusion 子元素,然后再在POM中显式地引入合适版本(3.3)的C依赖
</code></pre><p><img src="/images/image-20230917172717570.png" alt="image-20230917172717570"></p><blockquote><p>在exclusion元素中,只需给定groupId、artifactId即可确定依赖,而无需指定版本version</p></blockquote><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><dependencies></span></span>
<span class="line"><span style="color:#e1e4e8;"> <dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>com.apple</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>B</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <version>2.3</version></span></span>
<span class="line"><span style="color:#e1e4e8;"> <exclusions></span></span>
<span class="line"><span style="color:#e1e4e8;"> <exclusion></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>com.google</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>C</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> </exclusion></span></span>
<span class="line"><span style="color:#e1e4e8;"> </exclusions></span></span>
<span class="line"><span style="color:#e1e4e8;"> </dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> <dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>com.google</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>C</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <version>3.3</version> </span></span>
<span class="line"><span style="color:#e1e4e8;"> </dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"></dependencies></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><dependencies></span></span>
<span class="line"><span style="color:#24292e;"> <dependency></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>com.apple</groupId></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>B</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> <version>2.3</version></span></span>
<span class="line"><span style="color:#24292e;"> <exclusions></span></span>
<span class="line"><span style="color:#24292e;"> <exclusion></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>com.google</groupId></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>C</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> </exclusion></span></span>
<span class="line"><span style="color:#24292e;"> </exclusions></span></span>
<span class="line"><span style="color:#24292e;"> </dependency></span></span>
<span class="line"><span style="color:#24292e;"> <dependency></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>com.google</groupId></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>C</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> <version>3.3</version> </span></span>
<span class="line"><span style="color:#24292e;"> </dependency></span></span>
<span class="line"><span style="color:#24292e;"></dependencies></span></span></code></pre></div><h2 id="合理的依赖范围" tabindex="-1">合理的依赖范围 <a class="header-anchor" href="#合理的依赖范围" aria-label="Permalink to "合理的依赖范围""></a></h2><blockquote><p>依赖范围:控制依赖与三种classpath的关系,可在POM文件的依赖元素dependency中的scope元素中进行配置,缺省值 compile</p></blockquote><pre><code> Maven在编译、测试、运行(含打包)阶段中所需的依赖并不完全一致,所以Maven通过三种不同的classpath实现在不同阶段引入所需的依赖:编译classpath、测试classpath、运行classpath
</code></pre><h3 id="常见依赖范围" tabindex="-1">常见依赖范围 <a class="header-anchor" href="#常见依赖范围" aria-label="Permalink to "常见依赖范围""></a></h3><blockquote><p>常见的依赖范围有:</p></blockquote><ul><li><p><strong>compile</strong> :</p><p>不声明scope元素的情况下的<strong>默认值</strong>;compile表示被依赖包需要参与当前项目的编译,包括后续的测试,运行周期也参与其中,是一个比较强的依赖;打包的时候通常需要包含进去。</p></li><li><p><strong>provided</strong> :</p><p><code>provided</code> 类型的scope只会在项目的<code>编译</code>、<code>测试</code>阶段起作用;可以认为在目标容器中已经提供了这个依赖,无需在提供,但是在编写代码或者编译时可能会用到这个依赖;<code>依赖不会被打入到项目jar包中</code>。</p></li><li><p><strong>runtime</strong> :</p><p><code>runtime</code>与<code>compile</code>比较相似,区别在于<code>runtime</code> 跳过了<code>编译</code>阶段,打包的时候通常需要包含进去。</p></li></ul><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;">例:当你的代码需要使用jdbc连接一个mysql数据库,通常我们会希望针对标准 JDBC 抽象进行编码,而不是直接错误的使用 MySQL driver实现。这个时候依赖的scope就需要设置为runtime。这意味着我们在编译时无法使用该依赖,该依赖会被包含在最终的产物中,在程序最终执行时可以在classpath下找到它。</span></span>
<span class="line"><span style="color:#e1e4e8;"> <dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>mysql</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>mysql-connector-java</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <scope>runtime</scope></span></span>
<span class="line"><span style="color:#e1e4e8;"> </dependency></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;">例:当你的代码需要使用jdbc连接一个mysql数据库,通常我们会希望针对标准 JDBC 抽象进行编码,而不是直接错误的使用 MySQL driver实现。这个时候依赖的scope就需要设置为runtime。这意味着我们在编译时无法使用该依赖,该依赖会被包含在最终的产物中,在程序最终执行时可以在classpath下找到它。</span></span>
<span class="line"><span style="color:#24292e;"> <dependency></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>mysql</groupId></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>mysql-connector-java</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> <scope>runtime</scope></span></span>
<span class="line"><span style="color:#24292e;"> </dependency></span></span></code></pre></div><ul><li><p><strong>test</strong> :</p><p>在一般的编译和运行时都不需要,它们只有在测试编译和测试运行阶段可用,<code>不会被打包到项目jar包中</code>,同时如果项目A依赖于项目B,项目B中的<code>test</code>作用域下的依赖不会被继承。</p></li><li><p><strong>system</strong> :</p><p>系统依赖范围,其效果与provided的依赖范围一致。其用于添加非Maven仓库的本地依赖,通过依赖元素dependency中的systemPath元素指定本地依赖的路径。鉴于使用其会导致项目的可移植性降低,一般不推荐使用</p></li></ul><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><!--引用--></span></span>
<span class="line"><span style="color:#e1e4e8;"> <dependency></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>xxxx</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>xxx</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <systemPath>D:\tempare\itheima-maven-test-aaa-1.0-SNAPSHOT.jar</systemPath></span></span>
<span class="line"><span style="color:#e1e4e8;"> <scope>system</scope></span></span>
<span class="line"><span style="color:#e1e4e8;"> <version>1.4.12</version></span></span>
<span class="line"><span style="color:#e1e4e8;"> </dependency></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><!--引用--></span></span>
<span class="line"><span style="color:#24292e;"> <dependency></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>xxxx</groupId></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>xxx</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> <systemPath>D:\tempare\itheima-maven-test-aaa-1.0-SNAPSHOT.jar</systemPath></span></span>
<span class="line"><span style="color:#24292e;"> <scope>system</scope></span></span>
<span class="line"><span style="color:#24292e;"> <version>1.4.12</version></span></span>
<span class="line"><span style="color:#24292e;"> </dependency></span></span></code></pre></div><ul><li><p><strong>import</strong> :</p><p>import 只能在pom文件的中使用,从而引入其他的pom文件中引入依赖,如:在Spring boot 项目的POM文件中,我们可以通过在POM文件中继承 Spring-boot-starter-parent来引用Spring boot默认依赖的jar包,如下:</p><div class="language- vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki github-dark vp-code-dark"><code><span class="line"><span style="color:#e1e4e8;"><parent></span></span>
<span class="line"><span style="color:#e1e4e8;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <artifactId>spring-boot-starter-parent</artifactId></span></span>
<span class="line"><span style="color:#e1e4e8;"> <version>2.0.1.BUILD-SNAPSHOT</version></span></span>
<span class="line"><span style="color:#e1e4e8;"></parent></span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292e;"><parent></span></span>
<span class="line"><span style="color:#24292e;"> <groupId>org.springframework.boot</groupId></span></span>
<span class="line"><span style="color:#24292e;"> <artifactId>spring-boot-starter-parent</artifactId></span></span>
<span class="line"><span style="color:#24292e;"> <version>2.0.1.BUILD-SNAPSHOT</version></span></span>
<span class="line"><span style="color:#24292e;"></parent></span></span></code></pre></div><p>但是,通过上面的parent继承的方法,只能继承一个 spring-boot-start-parent。实际开发中,用户很可能需要继承自己公司的标准parent配置,这个时候可以使用 scope=import 来实现多继承。代码如下:</p><pre><code><dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.1.BUILD-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</code></pre><p>通过上面方式,就可以获取spring-boot-dependencies.2.0.1.BUILD-SNAPSHOT.pom文件中dependencyManagement配置的jar包依赖。如果要继承多个,可以在dependencyManagement中添加,如:</p><pre><code> <dependencyManagement>
<dependencies>
<!-- Override Spring Data release train provided by Spring Boot -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Fowler-SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.1.BUILD-SNAPSHOT</version>
<type>pom</type>