简体   繁体   English

Maven中Jetty插件的企业用途是什么?

[英]What is the enterprise use of the Jetty plugin in Maven?

Since I learn from some maven tutorials we can import Jetty as a maven plugin like this. 由于我从一些maven教程中学习,我们可以将Jetty导入为这样的maven插件。

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>maven-jetty-plugin</artifactId>
  <version>6.1.10</version>
  <configuration>
    <scanIntervalSeconds>5</scanIntervalSeconds>
  </configuration>
</plugin>

And can run the plugin like this. 并且可以像这样运行插件。

$ mvn jetty:run

Also we can change the port and context path and lots of stuff in this plugin. 此外,我们可以更改此插件中的端口和上下文路径以及许多内容。
As I understood that we can use Jetty as a server like tomcat, and we can deploy an application through it. 据我所知,我们可以将Jetty用作tomcat之类的服务器,我们可以通过它部署应用程序。

But the thing I don't understand is what is the actual enterprise use of Jetty in maven. 但我不明白的是,在maven中实际使用Jetty的企业什么。 .

From the official documentation : 官方文档

The Jetty Maven plugin is useful for rapid development and testing. Jetty Maven插件可用于快速开发和测试。 You can add it to any webapp project that is structured according to the Maven defaults. 您可以将其添加到根据Maven默认值构建的任何webapp项目。 The plugin can then periodically scan your project for changes and automatically redeploy the webapp if any are found. 然后,插件可以定期扫描您的项目以进行更改,并自动重新部署Web应用程序(如果有)。 This makes the development cycle more productive by eliminating the build and deploy steps: you use your IDE to make changes to the project, and the running web container automatically picks them up, allowing you to test them straight away. 这通过消除构建和部署步骤使开发周期更高效:您使用IDE对项目进行更改,并且正在运行的Web容器会自动选择它们,允许您立即测试它们。

However (and maybe this addresses what you call "enterprise use"): 但是(也许这可以解决您所谓的“企业使用”):

While the Jetty Maven Plugin can be very useful for development we do not recommend its use in a production capacity. 虽然Jetty Maven插件对于开发非常有用,但我们不建议将其用于生产。 In order for the plugin to work it needs to leverage many internal Maven apis and Maven itself it not a production deployment tool. 为了使插件能够工作,它需要利用许多内部Maven apis和Maven本身而不是生产部署工具。 We recommend either the traditional distribution deployment approach or using embedded Jetty. 我们建议使用传统的分发部署方法或使用嵌入式Jetty。

I don't know exactly what you mean by enterprise use , but let's say you're developing a web application and it's a Maven project. 我不确切地知道你对企业使用的意思,但是假设你正在开发一个Web应用程序,它是一个Maven项目。

Each time you want to test whether the web application works correctly, you need to deploy the web archive (WAR) on a web server, eg Jetty or Tomcat. 每次要测试Web应用程序是否正常工作时,都需要在Web服务器(例如Jetty或Tomcat)上部署Web存档(WAR)。 Usually this involves a couple of manual steps like: 通常这涉及几个手动步骤,如:

  1. Start the web server 启动Web服务器
  2. Deploy the WAR on it 在上面部署WAR

Where the Maven plugin comes in handy is that it allows you to just execute Maven插件派上用场的地方就是它允许你只执行

mvn jetty:run-war

and it does all these steps automatically for you in a single command, saving you lots of time. 它会在一个命令中自动为您完成所有这些步骤,从而为您节省大量时间。 The plugin is even able to redeploy the application once it notices changes have been made. 该插件甚至能够在应用程序发生更改后重新部署该应用程序。

The main usage is for testing, Jetty can also be started programmatically (see this example Java code) which means you can start server directly from your code and interact with your REST API for instance. 主要用于测试,Jetty也可以以编程方式启动(请参阅此示例 Java代码),这意味着您可以直接从代码启动服务器并与REST API进行交互。

You can also use it for easier deployment of small applications, just package everything into the JAR which runs server from main method when executed via java -jar your-app.jar . 您还可以使用它来更轻松地部署小型应用程序,只需将所有内容打包到JAR中,该JAR在通过java -jar your-app.jar执行时从main方法运行服务器。 You don't need any dependencies installed except Java then. 除了Java之外,您不需要安装任何依赖项。

As a side note, I currently work in Clojure (JVM language based on Lisp) and many people deploys their application as JAR which internally runs embedded Jetty because this way it's also starts REPL which you can connect to remotely and debug your application when it's running. 作为旁注,我目前在Clojure(基于Lisp的JVM语言)工作,许多人将他们的应用程序部署为JAR,内部运行嵌入式Jetty,因为这样它也可以启动REPL ,您可以远程连接并在运行时调试应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM