Technology Sharing

Maven7——(Important, build project) Maven project build (command)

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Maven's common commands manage the project life cycle
insert image description here
insert image description here

clean Command

Clear the target folder contents generated by compilation. You can use it with the corresponding commands in cmd, such as mvn clean package, mvn clean test
D: Work company training-4 shift day20day20untitled1>mvn clean
insert image description here

compile Command

This command can compile the code in the src/main/java directory
D: Work company training-4 shift day20day20untitled1>mvn compile
insert image description here

test Command

Test command, first compile the classes in src/main/java and src/test/java, and then execute all junit test cases in src/test/java/

• Create a test class DemoTest under src/test/java
insert image description here

• Execute the test command to test
D: Work company training-4 shift day20day20untitled>mvn test
insert image description here

• The console displays the test results
insert image description here

package command

mvn package, package the project
Compile first, then execute the test, and then package (only the code in main/java will be packaged. Is it the content in the compiled java package? Pay attention to the format of the compiled file after typing the code.)
So after compilation and packaging, the jar package contains .class files.
• If it is a JavaSe project, package it into a jar package
• If it is a JavaWeb project, package it into a war package
D: Work company training-4 shift day20day20untitled>mvn package
insert image description here

The packaged project will be found in the target directory
insert image description here

install command

mvn install, package and install it in the local repository
insert image description here

After installation, the information that can be found in the local warehouse
insert image description here

Notice:

life cycle:

When we execute install, we will also execute compile test package

! ! Use command to build in idea

insert image description here
insert image description here