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

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

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Bridging JavaScript and Java Packages: An Introduction to Npm2Mvn
  • Wow, pnpm, You’re Really Fast
  • Next Generation Front-End Tooling: Vite
  • Creating a Polar Chart to Measure Electromagnetic Field Strength

Trending

  • Integrating Model Context Protocol (MCP) With Microsoft Copilot Studio AI Agents
  • The Cypress Edge: Next-Level Testing Strategies for React Developers
  • AI’s Role in Everyday Development
  • Article Moderation: Your Questions, Answered
  1. DZone
  2. Coding
  3. Java
  4. Introducing the NPM Maven Plugin

Introducing the NPM Maven Plugin

By 
Ross Mason user avatar
Ross Mason
·
Oct. 01, 13 · Interview
Likes (1)
Comment
Save
Tweet
Share
18.5K Views

Join the DZone community and get the full member experience.

Join For Free
This post comes from Alberto Pose at the MuleSoft blog.

Introduction

Suppose that you have a Maven project and you want to download Node.js modules previously uploaded to NPM. One way of doing that without running node is by using the npm-maven-plugin. It allows the user to download the required Node modules without running node.js: It is completely implemented on the JVM.

Getting Started

First of all, you will need to add the Mule Maven repo to your pom.xml file:

<repository>
  <id>mulesoft-releases</id>
  <name>MuleSoft Repository</name>
  <url>https://repository.mulesoft.org/releases/</url> 
</repository>

After doing that, you will need to add the following to the build->plugin section of your pom.xml file:

<plugin>
    <groupId>org.mule.tools.javascript</groupId>
    <artifactId>npm-maven-plugin</artifactId>
    <version>1.0</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>fetch-modules</goal>
            </goals>
            <configuration>
                <packages>
                    <package>colors:0.5.1</package>
                    <package>jshint:0.8.1</package>
                </packages>
            </configuration>
        </execution>
    </executions>
</plugin>

Then just execute:

mvn generate-sources
and that’s it!

One more thing…

By default, the modules can be found in src/main/resources/META-INF but that path can be changed setting the ‘outputDirectory’ parameter.

Also, module transitivity is taken into account. That means that it will download all the required dependencies before downloading the specified module.

Show me the code!

The source code can be found here. Feel free to fork the project and propose changes to it.

Happy (Node.js and Maven) hacking!





Apache Maven Node.js Npm (software)

Published at DZone with permission of Ross Mason, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Bridging JavaScript and Java Packages: An Introduction to Npm2Mvn
  • Wow, pnpm, You’re Really Fast
  • Next Generation Front-End Tooling: Vite
  • Creating a Polar Chart to Measure Electromagnetic Field Strength

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!