Home Navigation

Thursday 6 October 2016

Publish file system library (jar, war, ear) to remote repository ( nexus) using maven deploy command.

I have created a batch script to publish all the libraries inside a directory, you have to just place the batch script in the directory and execute it.

Before you execute the script make sure that you have defined a server in maven settings.xml (it will be found in {USER_HOME}/.m2 directory)

<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <servers>
    <server>
      <id>central</id>
    </server>
    <server>
      <id>snapshots</id>
    </server>
    <server>
  <id>nexus</id> <!-- this is the repository id in batch script -->
  <username>deployment</username>
  <password>deployment123</password>
  </server>
  </servers>

Batch script to publish jars

@echo off
color 1f
::#############################################################################
cls
:start

set repositoryUrl=http://192.168.0.19:8082/nexus/content/repositories/releases/
set repositoryId=nexus
set packaging=jar
set groupId={give_a_group_id}
set versionId={give_a_version}

setlocal EnableDelayedExpansion

echo Reading jar files to publish nexus repository %repositoryUrl%
for %%a in (*.jar) do (
    echo deploying jar file %%~na
    call mvn deploy:deploy-file -DgroupId=%groupId% -DartifactId=%%~na -Dversion=%versionId% -Dpackaging=jar -Dfile=%%~na.jar -DrepositoryId=%repositoryId% -Durl=%repositoryUrl%              
               
)

echo Finished publishing to nexus repository %repositoryUrl%

pause > null

No comments:

Post a Comment