我正在尝试编写一个 24/7 运行的 Java 服务,从网络上抓取内容并将其存储到数据库中。鉴于我想...
1.)拥有一个可以将代码部署到的应用程序服务器(并让它自动运行)。该应用程序服务器应该位于与我的开发环境将运行的计算机分开的盒子上。
2.) 拥有一个开发平台(我更喜欢基于 eclipse 的平台),它允许我将代码直接部署到应用程序服务器(这样我就不必将所有内容都通过 ftp 进行测试)。
3.) 使用像 Spring 这样的框架。
实际上,我想知道为我的应用程序选择什么...
1.) 应用程序服务器
2.) 开发环境 (ide) -- 如果是 eclipse,使用什么服务器适配器
3.) 框架
到目前为止,我已经尝试使用 Virgo 和 SpringSource STS,但无法为非本地主机驻留服务器配置 Web 服务器适配器。我不想在我的开发机器上安装 Virgo,并且我不想将我的代码通过 ftp 跳转到我的生产服务器才能进行部署。
I'm trying to write a Java service which runs 24/7, scrapes content from the web, and stores it into a database. What is the best framework to use for this given that I'd like to...
1.) Have an application server that I can deploy my code to (and have it run automatically). This application server should sit on a separate box from the machine that my development environment will run on.
2.) Have a development platform (I would prefer something based on eclipse) which allows me to deploy my code directly to the application server (so I don't have to ftp everything over to test).
3.) Utilize a framework like Spring.
In effect, I'd like to know what to choose for my...
1.) application server
2.) development environment (ide) -- if eclipse, what server adapter to use
3.) framework
So far, I've tried using Virgo with SpringSource STS, but was unable to configure the web server adapter for a non-localhost-residing server. I don't want to have to install Virgo on my development box, and I don't want to have to ftp hop my code over to my production server in order to deploy.
发布评论
评论(3)
为什么不直接使用 Tomcat 或其他一些 Web 容器,但最好将其拆分为两个应用程序。
有一个可以出去进行抓取的应用程序,作为一个独立的应用程序,为此你可以选择任何东西,我会选择
Groovy
(http://groovy.codehaus.org/),因为这里易于开发和维护非常重要,并且您可以使用 Eclipse 的 Groovy 插件。另一个是网络服务,为此我认为
Scala
(http:// /www.scala-lang.org/)会很好,如果你有时间学习的话,但是Grails
(一个 groovy 框架)会很有帮助,所以你可以编写一个 REST或 SOAP Web 服务。通过将它们分开,您可以为该特定方面选择最佳解决方案,因为 Web 服务器不应该参与抓取,但 Web 服务器需要从数据库中读取数据。
这两种语言在 JVM 上运行,可以使用常规的 java 类/库,但它们比普通 Java 有所改进。
Why don't you just use Tomcat or some other web container, but it may be better to split this into two applications.
Have one that goes out and does the scraping, as a standalone application, for this you can pick anything, I would go with
Groovy
(http://groovy.codehaus.org/), as ease of development and maintenance is important here, and you can use the Groovy plugin for Eclipse.The other would be the web service and for this I would think
Scala
(http://www.scala-lang.org/) would be nice, if you have time to learn it, butGrails
(a groovy framework) would be beneficial, so you can write a REST or SOAP web service.By separating them then you can pick the best solution for that particular aspect, since the web server shouldn't be involved in scraping, but the web server will want to read from the database.
These two languages run on the JVM and can use regular java classes/libraries, but there are improvements over plain Java in them.
事实证明,有一些 Maven 插件可以为我远程部署我的应用程序。最值得注意的是 Cargo。这样,我可以保持所有初始工具/服务相同(Virgo、STS、Maven)。
Turns out there are some maven plugins that will remotely deploy my app for me. The most notable is Cargo. This way, I can keep all of my initial tools/services the same (Virgo, STS, Maven).
我最近实际上已经构建了类似的东西。我的应用程序可以在没有 servlet 容器或应用程序服务器的情况下运行。我选择在 Tomcat Servlet 引擎中运行应用程序的原因是,我可以向其中添加 REST API 以轻松检索服务器状态信息,但我离题了。
普通的 Eclipse J2EE 安装具有良好的 Tomcat 支持,因此在不了解更多关于您的品味和细节的情况下,我会选择它。
要使您的应用程序自启动,您需要实现
ServletContextListener
接口:将以下内容添加到您的
web.xml
中:您要使用哪个框架,只有您可以决定。你的问题太笼统了,无法给出合适的答案。阅读一些并选择一个。普通的旧 Java 也可以很好地工作,否则 Scala 可能是一个不错的替代选择。
所以,回答你的问题:
I've actually build something similar quite recently. My application could run without a servlet container or an application server. The reason I choose to run my app in a Tomcat servlet engine is so that I can add a REST API to it to easily retrieve server status information, but I digress.
The plain vanilla Eclipse J2EE installation has decent Tomcat support so without knowing more about your tastes and specifics I'd go with that.
To make your application self starting you need to implement the
ServletContextListener
interface:Add the following to your
web.xml
:Which framework you want to use, only you can decide. Your question is to generic to give a decent answer on that. Read up on a few and pick one. Plain old Java will also do just fine and otherwise Scala might be a good substitute choice.
So, to answer your questions: