简体   繁体   English

在生产中部署码头应用程序的一般方法是什么?

[英]What is the general way to deploy jetty application in production?

I just take over a project which is a java servlet application, I just figured out the way running the application is mvn jetty:run by using history .我刚刚接手了一个项目,它是一个 java servlet 应用程序,我刚刚弄清楚运行该应用程序的方式是mvn jetty:run by using history The previous only developer just quit suddenly, and there's no document.之前唯一的开发者突然退出,没有任何文件。 I have to create production server and deploy the application.我必须创建生产服务器并部署应用程序。

I have no previous Java experiences, so have not idea how to do it.我没有以前的 Java 经验,所以不知道该怎么做。 Should I install nginx or apache and run the application like PHP?我应该安装 nginx 或 apache 并像 PHP 那样运行应用程序吗? Or I just do something like nodejs ?或者我只是做类似nodejs的事情?

Jetty is a Java Servlet container/server (with many more features). Jetty 是一个 Java Servlet 容器/服务器(具有更多功能)。

There's no need for another server.不需要另一台服务器。

You have a few choices on how to start Jetty.关于如何启动 Jetty,您有几个选择。

  1. Standalone server using the jetty-home (or the older jetty-distribution ) tarballs.使用jetty-home (或较旧的jetty-distribution )tarball 的独立服务器。

    In this mode you unpack the jetty-home tarball (this will become the ${jetty.home} directory), create a new directory for your configuration / deployment (this will become the ${jetty.base} directory), and then run Jetty against this ${jetty.base} directory.在这种模式下,您解压jetty-home压缩包(这将成为${jetty.home}目录),为您的配置/部署创建一个新目录(这将成为${jetty.base}目录),然后运行Jetty 针对这个${jetty.base}目录。

    There are many many examples online of how to do this.网上有很多关于如何做到这一点的例子。

    From the official Jetty documentation at https://www.eclipse.org/jetty/documentation/current/来自https://www.eclipse.org/jetty/documentation/current/的官方 Jetty 文档

    To various examples here on stackoverflow.对于stackoverflow上的各种示例。

     # Grab the tarball [~]$ curl -O https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-home/9.4.30.v20200611/jetty-home-9.4.30.v20200611.tar.gz # Unpack the tarball [~]$ tar -zxvf jetty-home-9.4.30.v20200611.tar.gz # Make a {jetty.base} directory to house your configuration [~]$ mkdir myappbase [~]$ cd myappbase # Since this is a new {jetty.base}, lets initialize it with a # few common modules [myappbase]$ java -jar../jetty-home-9.4.30.v20200611/start.jar \ --add-to-start=http,deploy INFO: webapp transitively enabled, ini template available with --add-to-start=webapp INFO: server transitively enabled, ini template available with --add-to-start=server INFO: security transitively enabled INFO: servlet transitively enabled INFO: http initialized in ${jetty.base}/start.ini...(snip)... INFO: deploy initialized in ${jetty.base}/start.ini MKDIR: ${jetty.base}/webapps INFO: Base directory was modified # Lets see what we have now [myappbase]$ ls -F start.ini webapps/ # Copy your webapp into place [myappbase]$ cp ~/Projects/mywebapp.war webapps/ # See this Jetty Configuration [myappbase]$ java -jar../jetty-home-9.4.30.v20200611/start.jar --list-config # Run Jetty [myappbase]$ java -jar../jetty-home-9.4.30.v20200611/start.jar
  2. Embedded Jetty嵌入式码头

    This means you have initialized everything entirely in code, from the Server object, to the ServerConnector , to the WebAppContext (or the ServletContextHandler ) and are issuing a Server.start();这意味着您已经完全用代码初始化了所有内容,从Server object 到ServerConnector ,再到WebAppContext (或ServletContextHandler ),并且正在发出一个Server.start(); to make the Server execute.使服务器执行。

    This is probably the more common usage of Jetty, we find far more users on this approach then the standalone approach.这可能是 Jetty 更常见的用法,我们发现这种方法的用户比独立方法要多得多。

  3. For development using the jetty-maven-plugin使用 jetty-maven-plugin 进行开发

    This is what you have discovered already.这是你已经发现的。

    In a maven project with <packaging>war</packaging> you can execute the various jetty-maven-plugin goals to do various things with that maven project during development time.在带有<packaging>war</packaging>的 maven 项目中,您可以在开发期间执行各种jetty-maven-plugin目标以使用 maven 项目执行各种操作。

    NOTE: This mode is not suitable for production!注意:此模式不适合生产!

    jetty:run is the jetty-maven-plugin and the run goal. jetty:runjetty-maven-pluginrun目标。

    See: https://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html请参阅: https://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html

  4. Alternate environments where Jetty is embedded.嵌入 Jetty 的替代环境。

    This mode is seeing increasing use, and if your application is using libraries like Spark or SpringBoot then you are essentially using Jetty under the covers, and have no need for a separate server installation / configuration, it's all done within the API/SDK of that library.这种模式的使用越来越多,如果您的应用程序使用像 Spark 或 SpringBoot 这样的库,那么您实际上是在使用 Jetty,并且不需要单独的服务器安装/配置,这一切都在 API/SDK 中完成图书馆。

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

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