DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • How To Use Pandas and Matplotlib To Perform EDA In Python
  • Never Use Credentials in a CI/CD Pipeline Again
  • How To Use Geo-Partitioning to Comply With Data Regulations and Deliver Low Latency Globally
  • Chaining API Requests With API Gateway

Trending

  • How To Use Pandas and Matplotlib To Perform EDA In Python
  • Never Use Credentials in a CI/CD Pipeline Again
  • How To Use Geo-Partitioning to Comply With Data Regulations and Deliver Low Latency Globally
  • Chaining API Requests With API Gateway
  1. DZone
  2. Coding
  3. Java
  4. How to Manage Maven Third Party Jars

How to Manage Maven Third Party Jars

Zemian Deng user avatar by
Zemian Deng
·
Jun. 26, 13 · Interview
Like (1)
Save
Tweet
Share
11.47K Views

Join the DZone community and get the full member experience.

Join For Free

When you find yourself the need to load third party jars into Maven repository, there are few steps you normally do to test it out. You first install them locally into $HOME/.m2/repository, and then create your project pom that list those dependency. When things look good, then you deploy into your own hosted repository. The following scripts will help you perform these tasks.

TIP
If you have lot’s of jars under a group, it’s more conveninent to create an extra pom that list these dependency and install/deploy it into the repository as well. And then your project would only need to include one dependency with <type>pom</type>.
bin/mvn-install.sh
#!/usr/bin/env bash
#
# Install local jar files into Maven repository. The artifact name would be same
# as the filename minus the extension.
# :Author: Zemian Deng
# :Date: 2013/06/17
#
# Usage:
#   # Print as maven dependency used in pom file
#   mvn-install.sh mygroup 1.0.0 lib/*.jar
#
#   # Install jar files into local maven repo
#   RUN_TYPE=install mvn-install.sh mygroup 1.0.0 lib/*.jar
#
#   # Deploy jar files into remote maven repo
#   export REPO_URL=http://localhost/nexus/content/repositories/thirdparty
#   RUN_TYPE=deploy mvn-install.sh mygroup 1.0.0 lib/*.jar
#

# Capture command arguments and options
GROUP=$1
shift
VERSION=$1
shift
FILES="$@"
if [[ "$GROUP" == "" || "$VERSION" == "" || "$FILES" == "" ]]; then
 printf "ERROR: invalid arguments: GROUP VERSION FILES...\n"
 exit 1
fi

RUN_TYPE=${RUN_TYPE:="print"} # values: print|install|deploy
REPO_ID=${REPO_ID:="nexus-server"} # Id defined in user's settings.xml for authentication
REPO_URL=${REPO_URL:="http://localhost/nexus/content/repositories/thirdparty"}

# For each file, perform action based on run type.
for FILE in $FILES; do
 ARTIFACT=`basename $FILE '.jar'`
 if [[ "$RUN_TYPE" == "deploy" ]]; then
  printf "Deploying file=$FILE as artifact=$ARTIFACT to repo=$REPO_URL\n"
  mvn deploy:deploy-file \
   -DrepositoryId=$REPO_ID -Durl=$REPO_URL \
   -DgroupId=$GROUP -DartifactId=$ARTIFACT -Dversion=$VERSION -Dpackaging=jar \
   -Dfile=$FILE
 elif [[ "$RUN_TYPE" == "install" ]]; then
  printf "Installing file=$FILE as artifact=$ARTIFACT\n"
  mvn install:install-file \
   -DgroupId=$GROUP -DartifactId=$ARTIFACT -Dversion=$VERSION -Dpackaging=jar \
   -Dfile=$FILE
 elif [[ "$RUN_TYPE" == "print" ]]; then
  printf "        <dependency>\n"
  printf "            <groupId>$GROUP</groupId>\n"
  printf "            <artifactId>$ARTIFACT</artifactId>\n"
  printf "            <version>$VERSION</version>\n"
  printf "        </dependency>\n"
 fi
done
JAR (file format) Apache Maven

Published at DZone with permission of Zemian Deng, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • How To Use Pandas and Matplotlib To Perform EDA In Python
  • Never Use Credentials in a CI/CD Pipeline Again
  • How To Use Geo-Partitioning to Comply With Data Regulations and Deliver Low Latency Globally
  • Chaining API Requests With API Gateway

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: