Problem phenomenon:
Today I am thinking: How does maven package the projects on the Git warehouse (such as open source projects) into jar packages and import them into local projects as dependencies for use?
problem analysis:
This technique is often used: When you need to use some functions of a packaged project to complete the needs of a local project , because the project has many files, you don’t want to copy these files to the local project yourself. this way.
Solution:
1. First pull the GitHub warehouse project code to the local
Command: git clone git warehouse address
Here is a demonstration of graphical operations based on IDEA development tools :
Then open the project.
2. Type the project into a jar package and install it into the maven warehouse
Execute the commands in sequence : mvn clean package -DSkipTests and mvn clean install -DSkipTests
D:\Github Project\UserAgentParser>mvn clean package -DSkipTests
[INFO] Building jar: D:\Github Project\UserAgentParser\target\UserAgentParser-0.0.1.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 25.845 s
[INFO] Finished at: 2019-04-09T14:57:39+08:00
[INFO] Final Memory: 19M/210M
[INFO] ------------------------------------------------------------------------
D:\Github Project\UserAgentParser>mvn clean install -DSkipTests
[INFO] Installing D:\Github Project\UserAgentParser\target\UserAgentParser-0.0.1.jar to C:\Users\ghc\.m2\repository\com\kumkee\UserAgentParser\0.0.1\UserAgentParser-0.0.1.jar
[INFO] Installing D:\Github Project\UserAgentParser\pom.xml to C:\Users\ghc\.m2\repository\com\kumkee\UserAgentParser\0.0.1\UserAgentParser-0.0.1.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.027 s
[INFO] Finished at: 2019-04-09T14:58:51+08:00
[INFO] Final Memory: 19M/217M
[INFO] ------------------------------------------------------------------------
Here is a demonstration of graphical operations based on IDEA development tools . Click the operations in the figure in order. Pay attention to the information on the Terminal console . If BUILD SUCCESS appears, it means success:
3. Add maven dependency in the project pom.xml
You can look at the pom.xml file in the git warehouse project you need to Clone . There will be the following required information in it, just fill it in, such as:
<dependency>
<groupId>cn.stephen</groupId>
<artifactId>DemoProject</artifactId>
<version>0.0.1</version>
</dependency>