Upload jar package to nexus maven warehouse via command line

Some nexus versions do not support uploading jar packages directly on the management platform page,

Let me share how to manually upload the jar package to the maven warehouse through the command line:

 

Method 3 is currently the most effective

 

1: Upload directly to Maven:        
    mvn install:install-file -Dfile=fszrDBC-0.0.1-SNAPSHOT.jar -DgroupId=com.fszr.main -DartifactId=fszrDBC -Dversion=0.0.1 -Dpackaging=jar    
    mvn install: install-file -Dfile=cpcn-payment-api-2.4.0.6.jar -DgroupId=com.fszr.main -DartifactId=cpcn-payment-api -Dversion=2.4.0.6 -Dpackaging=jar    
This is just put in the maven warehouse , It’s not put in nexus and cannot be downloaded through nexus

 

2: Upload to the maven warehouse of Nexus

After putting the jar package in the same level directory as pom.xml, change pom.xml to pom.xml of your own jar package, and execute: mvn deploy

 

pom file content:

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.fadada.sdk</groupId>
	<artifactId>fadada_api_sdk</artifactId>
	<version>2.4.0</version>
	<packaging>jar</packaging>
	<name>fadada_api_sdk</name>
	<description>fadada_api_sdk_20190923</description>

	<distributionManagement>
		<repository>
			<id>nexus</id>
			<name>four_party</name>
			<url>http://192.168.20.129:8081/repository/four_party/</url>
		</repository>

	</distributionManagement>
	
	<!-- 执行mvn deploy即可上传成功! -->
</project>

 

3: It may not work with 2 upload, there is also method 3

Create a new directory on the Nexus home directory: repo    

 

To compress the jar to be uploaded, you must select the folder compression in the repository directory

 

For example, if you want to upload a jar package under com, but you don’t need so many other files under com, you can make a com folder by yourself until the final directory of the jar is                                
like com\api\jxtlt-sdk\1.0. You can create it yourself, and finally put the jar and pom into it                                
or directly copy the repository in the above .m2                

 

Upload to the /home/repo of the Nexus machine, and then decompress it. After decompression:

 

Execute the command: vi mavenimport.sh

Paste the following content in:

#!/bin/bash
 
# copy and run this script to the root of the repository directory containing files
# this script attempts to exclude uploading itself explicitly so the script name is important
# Get command line params
while getopts ":r:u:p:" opt; do
	case $opt in
		r) REPO_URL="$OPTARG"
		;;
		u) USERNAME="$OPTARG"
		;;
		p) PASSWORD="$OPTARG"
		;;
	esac
done
 
find . -type f -not -path './mavenimport\.sh*' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml' -not -path '*/\^maven\-metadata\-deployment*\.xml' | sed "s|^\./||" | xargs -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{} ;

 

After saving and exit, execute the authorization command: chmod +x mavenimport.sh and

execute the upload command: ./mavenimport.sh -u admin -p admin123 -r http://192.168.20.129:8081/repository/four_party/

 

 

 

 

 

Guess you like

Origin blog.csdn.net/u013282737/article/details/109290967