在生产中部署 Jetty 应用程序的一般方法是什么?
What is the general way to deploy jetty application in production?
我刚刚接手一个项目,它是一个 java servlet 应用程序,我刚刚弄清楚 运行 应用程序 mvn jetty:run
的方式 history
。之前唯一的开发者突然退出,没有文档。我必须创建生产服务器并部署应用程序。
我以前没有 Java 经验,所以不知道该怎么做。我应该安装 nginx 还是 apache 和 运行 像 PHP 这样的应用程序?或者我只是做类似 nodejs
?
的事情
Jetty 是一个 Java Servlet container/server(具有更多功能)。
不需要另一个服务器。
关于如何启动 Jetty,您有几个选择。
使用 jetty-home
(或较旧的 jetty-distribution
)tarball 的独立服务器。
在此模式下,您解压缩 jetty-home
tarball(这将成为 ${jetty.home}
目录),为您的配置/部署创建一个新目录(这将成为 ${jetty.base}
目录),然后 运行 Jetty 针对此 ${jetty.base}
目录。
网上有很多关于如何执行此操作的示例。
来自 https://www.eclipse.org/jetty/documentation/current/
的官方 Jetty 文档
到 Whosebug 上的各种示例。
# 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
嵌入式 Jetty
这意味着您已经完全用代码初始化了所有内容,从 Server
对象到 ServerConnector
,再到 WebAppContext
(或 ServletContextHandler
)并且是发出 Server.start();
让服务器执行。
这可能是 Jetty 更常见的用法,我们发现使用这种方法的用户比独立方法多得多。
使用 jetty-maven-plugin 进行开发
这是您已经发现的。
在具有 <packaging>war</packaging>
的 Maven 项目中,您可以执行各种 jetty-maven-plugin
目标,以便在开发期间对该 Maven 项目执行各种操作。
注意:此模式不适合生产!
jetty:run
是 jetty-maven-plugin
和 run
的目标。
参见:https://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html
嵌入 Jetty 的替代环境。
这种模式的使用越来越多,如果您的应用程序正在使用像 Spark 或 SpringBoot 这样的库,那么您实际上是在幕后使用 Jetty,不需要单独的服务器安装/配置,这一切都在API/SDK 那个图书馆。
我刚刚接手一个项目,它是一个 java servlet 应用程序,我刚刚弄清楚 运行 应用程序 mvn jetty:run
的方式 history
。之前唯一的开发者突然退出,没有文档。我必须创建生产服务器并部署应用程序。
我以前没有 Java 经验,所以不知道该怎么做。我应该安装 nginx 还是 apache 和 运行 像 PHP 这样的应用程序?或者我只是做类似 nodejs
?
Jetty 是一个 Java Servlet container/server(具有更多功能)。
不需要另一个服务器。
关于如何启动 Jetty,您有几个选择。
使用
jetty-home
(或较旧的jetty-distribution
)tarball 的独立服务器。在此模式下,您解压缩
jetty-home
tarball(这将成为${jetty.home}
目录),为您的配置/部署创建一个新目录(这将成为${jetty.base}
目录),然后 运行 Jetty 针对此${jetty.base}
目录。网上有很多关于如何执行此操作的示例。
来自 https://www.eclipse.org/jetty/documentation/current/
的官方 Jetty 文档到 Whosebug 上的各种示例。
# 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
嵌入式 Jetty
这意味着您已经完全用代码初始化了所有内容,从
Server
对象到ServerConnector
,再到WebAppContext
(或ServletContextHandler
)并且是发出Server.start();
让服务器执行。这可能是 Jetty 更常见的用法,我们发现使用这种方法的用户比独立方法多得多。
使用 jetty-maven-plugin 进行开发
这是您已经发现的。
在具有
<packaging>war</packaging>
的 Maven 项目中,您可以执行各种jetty-maven-plugin
目标,以便在开发期间对该 Maven 项目执行各种操作。注意:此模式不适合生产!
jetty:run
是jetty-maven-plugin
和run
的目标。参见:https://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html
嵌入 Jetty 的替代环境。
这种模式的使用越来越多,如果您的应用程序正在使用像 Spark 或 SpringBoot 这样的库,那么您实际上是在幕后使用 Jetty,不需要单独的服务器安装/配置,这一切都在API/SDK 那个图书馆。