如果我想在后台运行 Java 代码,我应该使用什么 Web 服务器?
目前,我有很多 Java,它们可以做各种漂亮的事情,我对此很满意。该代码是命令行驱动的,到目前为止效果很好,但我最近决定通过 Web 服务提供该功能。由于我的语言很复杂并且我对它的编写方式很满意,所以我不想经历将其移植到其他语言的痛苦。因此,我开始了一次谷歌之旅,寻找存在哪些网络服务器(在 Linux 机器上,尽管在没有这种限制的情况下听到答案很有趣)。
据我所知,似乎有两个可行的选择: Apache Tomcat 和 Sun Java 服务器。
选择其中一个而不是另一个的原因是什么?每个人的优点是什么,缺点是什么?或者,也许还有第三种方法,它更容易、灵活且不那么麻烦。
有人吗?
At the moment, I have lot's of Java which does all kind of nifty stuff and I'm happy with it. The code is command line driven which have been great so far, but I recently decided I want to make the functionality available through web-services. Since my is complex and I'm happy with the way it's written , I don't want go through the pain of porting it to other languages. So I set out on a google journey to find out what web servers exist (on a Linux machine, though it's interesting to hear the answer without that limitation).
From what I could find, it seems that there are two viable options: Apache Tomcat and Sun Java Server.
What are the reason to choose one on top of the other? what are the strength of each and what are the weaknesses? Or, perhaps, there is a third one which is much easier, flexible and less cumbersome.
Anyone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
简单、灵活且不麻烦,那就是Jetty,而且Simpleweb 可能有用。你没有对你的软件说太多,所以我不太确定,但对于命令行程序,我认为你不需要所有的 JavaEE 东西。
主流服务器是这些。
我认为 Apache Tomcat 与 Glassfish (Sun Java Server) 的讨论与您的需求无关,任何都可以。
Easy, flexible and not cumbersome, that would be Jetty, but also Simpleweb might be useful. You dont say much about your software so i'm not really sure, but for a command line program, I don't think you need all the JavaEE stuff.
The mainstream servers are these.
I think the Apache Tomcat vs Glassfish (Sun Java Server) discussion is irrelevant for your needs, any would do.
Java Web 应用程序有许多容器,它们都有自己的优点和缺点。如果您正在寻找一个容器来支持业务应用程序,您可能应该看看它们有何不同,并找出适合您的业务和 IT 驱动因素的容器。
关键是它们都支持 servlet 规范 - 您的 Web 应用程序可以在其中任何一个中运行 - 这意味着您可以轻松改变主意。其中一些还将支持更多 Java 企业版规范,因此可能对于您的需求来说太重了。
如果您刚刚开始,我建议您使用 Tomcat。它很基础,但很可靠,运行和启动速度很快,并且有一个非常简单的基于 Web 的 Web 应用程序部署界面。
There are many containers for Java web applications, they all have their own strengths and weaknesses. If you're looking for a container to support a business application, you should probably take a look at how they differ and work out which suits your business and IT drivers.
The key thing is that they all support the servlet specification - your webapps can run in any of them - which means you can change your mind easily. Some of them will also support more of the Java Enterprise Edition specs, so may be too heavy for your needs.
If you're just getting started, I'd suggest Tomcat. It's basic, but it's reliable, quick to run and start up, and it's got a really easy web-based webapp deployment interface.
你的问题实际上有点太含糊和宽泛了。事实上,您可以在您喜欢的任何机器上运行 Java 代码,无论您使用哪种语言编写基于 Web 的界面。例如,您可以创建一个基于 PHP 的网站,该网站与“后端”Java 应用程序交互(正如您所说的“命令行应用程序”)。唯一的要求是服务器计算机上有 JRE。那么基本上所有的 Web 界面就足够了:CGI、PHP、ASP、Python 等等,凡是你能想到的。只要它能够访问底层命令行运行时,这在 PHP 示例中是由 exec() 完成的。
但是 Java,实际上是 Java EE,还提供了一个 Web 应用程序编程接口:JSP/Servlet API,大型 Java EE API。这使得与“命令行 Java 应用程序”的集成更加无缝。基本上,您可以将应用程序放在类路径中,然后以真实 Java 方式在
Servlet
类中导入/访问/使用它:能够运行 JSP/Servlet (JSP最后实际上也是一个 Servlet),您需要 Servlet API 的具体实现(整个 Java EE 只是一个抽象规范)。 Apache Tomcat 是很好的开始,另一个流行的替代方案是 Eclipse Jetty。这些是实现 Servlet API 的“简单”servlet 容器,而 Jetty 是一种更加嵌入式的方法(您可以将其配置为“普通”Java 应用程序并运行)。但如果您还需要支持/涵盖 Java EE API 的其他方面,那么您需要一个应用程序服务器,例如 Sun Glassfish 或 JBoss AS (顺便说一下,两者都使用 Tomcat 作为servlet 容器部分)。
要了解有关 JSP/Servlet 的更多信息,我可以推荐 Coreservlets.com 教程 。
Your question is actually a bit too ambiguous and wide. You can in fact run Java code at any machine you like, regardless of the language you programmed the webbased interface in. You can for example create a PHP based website which interacts with a "backend" Java application (the "command line application" as you call it). The only requirement is to have a JRE at the server machine. Then basically everything as web interface suffices: CGI, PHP, ASP, Python, etcetera, you name it. As long as it has access to the underlying commandline runtime, which is in the PHP example to be done by
exec()
.But Java, actually Java EE, also provides a web application programming interface: the JSP/Servlet API, the web component of the large Java EE API. This make integration with the "commandline Java application" much more seamless. You can basically just put your application in the classpath and import/access/use it in a
Servlet
class the real Java way:To be able to run JSP/Servlet (JSP is at end actually also a Servlet), you need a concrete implementation of the Servlet API (the whole Java EE is just an abstract specification). Apache Tomcat is good to start with, the other popular alternative being Eclipse Jetty. Those are 'simple' servletcontainers which implements the Servlet API, with Jetty being a more embedded approach of it (you can configure and run it as a "plain vanilla" Java Application). But if you need to support/cover the other aspects of the Java EE API as well, then you need an application server, such as Sun Glassfish or JBoss AS (both which by the way uses Tomcat as the servletcontainer part).
To learn more about JSP/Servlet, I can recommend the Coreservlets.com tutorials.
Apache Tomcat 应该做得很好。
Apache Tomcat should do good.
在 Web 服务器内运行代码的标准概念是 Sun 的“Servlet API”。
本质上,它提供了一些 Web 服务器用来调用代码的接口,并定义了 Web 服务器的行为方式。这允许您编写非常通用的代码,可以在实现 Servlet API 的各种 Web 容器中运行。有关详细信息,请参阅维基百科文章 - http://en.wikipedia.org/wiki/Java_Servlet 。
它们也有各种尺寸,具体取决于您的需求。有些足够小,可以嵌入到您自己的应用程序中,有些非常。 Servlet API 让您无需关心。
对于初学者来说,最快的启动和运行方法是下载完整版本的 Netbeans,其中包括对此类工作的完全支持,并且具有内置的 servlet 容器。
The standard concept for running code inside a web server is the "Servlet API" from Sun.
Essentially it provides a few interfaces which the web server uses to invoke your code, and defines how the web server should behave. This allows you to write very generic code that can run in a variety of web containers which implement the Servlet API. See the Wikipedia article for details - http://en.wikipedia.org/wiki/Java_Servlet.
They come in all sizes too, depending on your needs. Some small enough for embedding in your own application, some very big. The servlet API allows you not to care.
For a beginner, the quickest way to get up and running, is to download the full version of Netbeans which includes full support for doing this kind of work, and has a built in servlet container.