Series Article Directory
1. Linux installation Nexus3.42.0-01 graphic tutorial
2. Nexus create Maven private server graphic tutorial
3. Use nexus to upload jar package graphic tutorial
4. IDEA Maven project upload jar package to nexus warehouse graphic tutorial
5. Use in IDEA Maven downloads jar package graphic tutorial from nexus
The maven command uploads the jar package to nexus
- Series Article Directory
- foreword
- 1. What is maven?
- Two, use
- problem record
-
- 1.Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy-file (default-cli) on project Failed to deploy artifacts: Could not transfer artifact with status code 401
- 2.Cannot deploy artifact from the local repository
- 3.Maven报错-The goal you specified requires a project to execute but there is no POM in this directory..
- Summarize
foreword
For projects that integrate maven, such as the maven project in idea, the project can be deployed to the remote repository through the deploy:deploy command. So for a project that does not integrate maven, how to deploy the project to a remote repository? This article mainly introduces uploading resources to the remote repository (nexus) by directly using the maven command.
Refer to the official website address:
Apache Maven Deployment Plugin – Usage
Maven – Available Plugins (apache.org)
1. What is maven?
Maven is a tool that provides build and dependency management support for Java projects
As a dependency management tool, Maven can manage large-scale jar packages and download dependent jars.
Maven is a build management tool. When we use IDEA for development, IDEA does the building work for us. After leaving the IDEA environment, we need special tools. Maven can help us build jar packages
Two, use
1. First add in maven's settings.xml file
settings.xml file (example):
!--nexus服务器-->
<servers>
<!--id为对应资源库id-->
<server>
<id>tfjy-snapshot-hosted</id>
<username>admin</username>
<password>nexusb-test</password>
</server>
<server>
<id>tfjy-hosted</id>
<username>admin</username>
<password>nexusb-test</password>
</server>
</servers>
2. The corresponding maven command
Maven command syntax:
mvn deploy:deploy-file
-DgroupId=xxx.xxx.xxx (corresponding to pom file label)
-DartifactId=xxx-xxx (corresponding to pom file label)
-Dversion=xxx (corresponding to pom file label)
-Dpackaging=xxx (upload type )
-Dfile=xxx:\xxx\xxx. (file path)
-DpomFile=xxxx indicates the absolute path of the Pom file corresponding to the jar package to be uploaded.
-Durl=http://xxx.xxx.xx:xxxx/xxx (uploaded server)
-DrepositoryId=xxxxx (server ID, serverId configured in the setting.xml file, used to associate the username and password of the private server)
Note: If the currently uploaded Jar also depends on other Jars, the pom file of the current Jar needs to be uploaded at the same time.
2.1 Upload resources as pom or jar packages to remote resource libraries
Code example: Open the Windows command prompt (Windows+R, enter cmd and press Enter); enter the mvn command, and the resource uploaded here is only the pom file.
mvn deploy:deploy-file -DgroupId=com.tfjybj -DartifactId=metaversePro-backend -Dversion=1.0-SNAPSHOT -Dpackaging=pom -Dfile=F:\maven\metaversePro-backend\1.0-SNAPSHOT\metaversePro-backend-1.0-SNAPSHOT.pom -Durl=http://xxxxx/repository/tfjy-snapshot-hosted/ -DrepositoryId=tfjy-snapshot-hosted
Screenshot of the result:
Check in the remote resource library, you can see that the uploaded resources have been uploaded.
2.2 Upload the jar package and this jar also depends on other Jar, and upload the pom file of the current Jar at the same time
Code example: The difference is that you need to add -DpomFile=
mvn deploy:deploy-file "-DgroupId=com.tfjybj" "-DartifactId=metaversePro-backend" "-Dversion=1.0-SNAPSHOT" "-Dpackaging=jar" "-Dfile=E:\Dynamic Time Programma\metaversePro-backend\metaversePro-gateway\target\metaversePro-gateway-1.0-SNAPSHOT.jar" "-DpomFile=E:\Dynamic Time Programma\metaversePro-backend\metaversePro-gateway\pom.xml" "-Durl=http://xxxx/repository/tfjy-snapshot-hosted/" "-DrepositoryId=tfjy-snapshot-hosted"
Screenshot of the result:
Check in the remote resource library, you can see that the uploaded resources have been uploaded.
problem record
1.Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy-file (default-cli) on project Failed to deploy artifacts: Could not transfer artifact with status code 401
Solution : Generally, the identity verification credentials are not passed. Check whether the account password of nexus in the settings.xml configuration is correct, whether the settings.xml file used is correct, and whether other settings.xml files are used.
2.Cannot deploy artifact from the local repository
Solution : Maven's deploy:deploy-file command, this method should be noted that if the jar and pom you want to install are located in the directory of the local repository, this command will make an error (Cannot deploy artifact from the local repository... ), solution: copy the jar and pom to be installed to another directory and then install it, as long as it is not in the local warehouse directory, it should be fine.
3.Maven报错-The goal you specified requires a project to execute but there is no POM in this directory…
Workaround : Enclose the command in double quotes ("")
Example:
mvn deploy:deploy-file "-DgroupId=com.tfjybj" "-DartifactId=metaversePro-backend" "-Dversion=1.0-SNAPSHOT" "-Dpackaging=jar" "-Dfile=E:\Dynamic Time Programma\metaversePro-backend\metaversePro-gateway\target\metaversePro-gateway-1.0-SNAPSHOT.jar" "-DpomFile=E:\Dynamic Time Programma\metaversePro-backend\metaversePro-gateway\pom.xml" "-Durl=http://xxxx/repository/tfjy-snapshot-hosted/" "-DrepositoryId=tfjy-snapshot-hosted"
Summarize
According to the maven official website, there are two main ways to deploy to the remote repository through the maven plug-in. One is that the project integrates maven and can be implemented through maven's deploy:deploy; the other is that the project does not integrate maven. We can use it in the command prompt Use the deploy:deploy-file command to achieve.