如何使用 maven 部署 node.js 应用程序? [英] How to deploy a node.js app with maven?

查看:94
本文介绍了如何使用 maven 部署 node.js 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的大部分团队由java开发人员组成,因此整个构建/部署/依赖管理系统都是建立在maven之上的.我们使用 CI,因此每个构建过程都运行单元测试(前端使用 karma 和 phantomJS,后端使用 jasmine-node).为此,我设法配置了一个 karma maven 插件.

Most of our team consists of java developers and therefore the whole build / deployment / dependency management system is built on top of maven. We use CI so every build process runs unit test (w. karma and phantomJS for the frontend, and jasmine-node for the backend). I've managed to configure a karma maven plugin for this purpose.

这并没有解决在构建时从 package.json 下载 node.js 依赖项的问题. 我需要在现有环境中部署我的 node.js/express 应用程序,所以完美的场景是:

This does not solve the issue of downloading node.js dependencies from package.json on build. I need to deploy my node.js / express app in existing environment, so the perfect scenario would be:

  1. 从 repo 中拉取(使用 Maven 构建自动完成)
  2. npm install(即 - 从节点包注册表下载依赖项)
  3. 运行测试
  1. pull from the repo (done automatically with maven build)
  2. npm install (that is - downloading dependencies from node package registry)
  3. running tests

我试图为 maven 寻找一个 nodejs 包,但老实说 - 作为一个 node.js 开发人员,我在选择正确的工具时不是很自信,因为我无法区分坏的来自一个不错的 maven 插件.

I was trying to find a nodejs package for maven, but to be honest - as a node.js developer I do not feel very confident when it comes to choosing the right tools, since I'm not able to distinguish a bad maven plugin from a decent one.

也许使用 shell 插件并从终端调用 npm install 是更好的选择?

Maybe using a shell plugin and invoking npm install from the terminal is a better choice?

你有什么看法?

推荐答案

您有两个选择:

  • https://github.com/eirslett/frontend-maven-plugin to let maven download your npm modules from your package.json and let it automagically install node and npm all along

https://github.com/mulesoft/npm-maven-plugin 让 maven 下载您在 pom.xml 中指定的 npm 包(链接截至 2020 年 4 月已失效,似乎已停止使用)

https://github.com/mulesoft/npm-maven-plugin to let maven download your npm packages that you have specified in the pom.xml (link dead as of April 2020, seems to be discontinued)

作为一个 hacky 解决方案,虽然仍然可行,但你可以像你自己提到的那样,使用类似 maven-antrun-plugin 的东西来实际使用 maven 执行 npm.

As a hacky solution, though still feasible you could as you've mentioned yourself, use something like maven-antrun-plugin to actually execute npm with maven.

所有方法都有其优点和缺点,但 frontend-maven-plugin 似乎是最常用的方法 - 但它假定您的 ci 服务器可以从互联网上下载任意包,而hacky"解决方案也应该有效, 当您的 ci 服务器根本没有连接到互联网时(除了代理中央 maven 存储库)

All approaches have their pros and cons, but frontend-maven-plugin seems to be the most often used approach - but it assumes that your ci server can download from the internet arbitrary packages, whereas the "hacky" solution should also work, when your ci server has no connection to the internet at all (besides proxying the central maven repo)

这篇关于如何使用 maven 部署 node.js 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆