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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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
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

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • AWS WAF Classic vs WAFV2: Features and Migration Considerations
  • Redefining Artifact Storage: Preparing for Tomorrow's Binary Management Needs
  • AWS CDK: Infrastructure as Abstract Data Types, Part 2
  • Understanding the Power of AWS Organizations: Streamlining Cloud Management

Trending

  • AI-Driven Root Cause Analysis in SRE: Enhancing Incident Resolution
  • Manual Sharding in PostgreSQL: A Step-by-Step Implementation Guide
  • Metrics at a Glance for Production Clusters
  • Exploring Intercooler.js: Simplify AJAX With HTML Attributes
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Host Your Maven Artifacts Using Amazon S3

Host Your Maven Artifacts Using Amazon S3

If you are looking for somewhere to host your artifacts, using AWS bring you halfway there. Follow these steps for the rest of the process.

By 
Emmanouil Gkatziouras user avatar
Emmanouil Gkatziouras
DZone Core CORE ·
Apr. 13, 18 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
38.1K Views

Join the DZone community and get the full member experience.

Join For Free

If you use Amazon Web Services and you use Java for your projects, then Amazon S3 is a great place to host your team's artifacts.

It is easy to setup and pretty cheap. Also, it is much simpler than setting one of the existing repository options (JFrog, Nexus, Archiva, etc.) if you are not particularly interested in their features.

To get started you need to specify a Maven wagon which supports S3.
We will use the S3 storage wagon.

Let’s get started by creating a Maven project.

mvn archetype:generate -DgroupId=com.test.apps -DartifactId=S3WaggonTest -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false


We are going to add a simple service.

package com.test.apps;

public class HelloService {

    public String sayHello() {

        return "Hello";
    }
}


Then we are going to add the Maven wagon which will upload and fetch our binaries to S3.

<build>
    <extensions>
        <extension>
            <groupId>com.gkatzioura.maven.cloud</groupId>
            <artifactId>s3-storage-wagon</artifactId>
            <version>1.0</version>
        </extension>
    </extensions>
</build>


Then we shall create the S3 bucket that will host our artifacts.

aws s3 createbucket artifactbucket


Now we have to create our bucket. Then we shall set the distribution management on our Maven project.

<distributionManagement>
    <snapshotRepository>
        <id>my-repo-bucket-snapshot</id>
        <url>s3://my-test-repo/snapshot</url>
    </snapshotRepository>
    <repository>
        <id>my-repo-bucket-release</id>
        <url>s3://my-test-repo/release</url>
    </repository>
</distributionManagement>


From the Maven documentation:

Whereas the repositories element specifies in the POM the location and manner in which Maven may download remote artifacts for use by the current project, distributionManagement specifies where (and how) this project will get to a remote repository when it is deployed. The repository elements will be used for snapshot distribution if the snapshotRepository is not defined.

The next step is the most crucial and this has to to do with authenticating to AWS. The easy way is to have AWS CLI configured to point to the region where your bucket is located and with credentials which have read and write access to the s3 bucket which will host your binaries.

aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: json


The other way is to use the Maven way and specify our AWS credentials on the ~/.m2/settings.xml

<servers>
  <server>
    <id>my-repo-bucket-snapshot</id>
    <username>EXAMPLEEXAMPLEXAMPLE</username>
    <password>eXampLEkeyEMI/K7EXAMP/bPxRfiCYEXAMPLEKEY</password>
  </server>
  <server>
    <id>my-repo-bucket-release</id>
    <username>EXAMPLEEXAMPLEXAMPLE</username>
    <password>eXampLEkeyEMI/K7EXAMP/bPxRfiCYEXAMPLEKEY</password>
  </server>
</servers>


Be aware that you have to specify credentials for each repository specified. We are not done yet, as it is crucial to specify the region of the bucket.

To do so, you can either set it up the Amazon way, thereby specifying it in an environmental variable:

AWS_DEFAULT_REGION=us-east-1



Or you can pass it as a property while executing the deploy command.

-DAWS_DEFAULT_REGION=us-east-1


And now the easiest part, which is deploying.

mvn deploy


Now since your artifact has been deployed you can use it in another repo by specifying your repository and your wagon.

<repositories>
    <repository>
        <id>my-repo-bucket-snapshot</id>
        <url>s3://my-test-repo/snapshot</url>
    </repository>
    <repository>
        <id>my-repo-bucket-release</id>
        <url>s3://my-test-repo/release</url>
    </repository>
</repositories>

<build>
    <extensions>
        <extension>
            <groupId>com.gkatzioura.maven.cloud</groupId>
            <artifactId>s3-storage-wagon</artifactId>
            <version>1.0</version>
        </extension>
    </extensions>
</build>


That’s it! Next thing you know your artifact will be downloaded by Maven through S3 and used as a dependency in your new project.

AWS Apache Maven Host (Unix) Artifact (UML) Amazon Web Services

Published at DZone with permission of Emmanouil Gkatziouras, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • AWS WAF Classic vs WAFV2: Features and Migration Considerations
  • Redefining Artifact Storage: Preparing for Tomorrow's Binary Management Needs
  • AWS CDK: Infrastructure as Abstract Data Types, Part 2
  • Understanding the Power of AWS Organizations: Streamlining Cloud Management

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!