通过 Jetty 在 Eclipse RCP 应用程序中部署 Struts2 WebApp

Deploy Struts2 WebApp Within An Eclipse RCP Application Via Jetty

现在给你一个烂摊子...

我目前正在开发 Eclipse RCP 应用程序插件。这个插件的目标是为用户提供一个 web 应用程序,以便在 Eclipse ViewPart(SWT 浏览器控件)中进行交互。

我希望此 Web 应用程序由 Struts2 提供支持,并且我已经可以使用 Jetty 来提供服务。

有什么办法可以用这种方式部署 Struts2 WebApp 吗?如果需要更多信息,请询问!

编辑#1:

更多细节。目前我知道如何部署 struts2 应用程序的唯一方法是通过 war 文件(托管在 tomcat 上)。在这种情况下,这不是我能做的。我需要使用 Eclipse RCP 框架提供的 Jetty 服务器以某种方式在内部以嵌入式方式部署 struts2。

结果:

事实证明,您可以使用嵌入式 Jetty 部署 WAR 文件(在本例中为 struts2 应用程序)。我发现 Joakim Erdfelt 在这里这样做:Embedding Jetty as a Servlet Container

Struts2 Web 应用程序可以 运行 在像 Jetty 这样的 servlet 容器中。 Jetty 也有一个嵌入式选项。 Eclipse RCP 使用 Eclipse 平台通过插件进行扩展和定制。 using Eclipse RCP with embedded Jetty server 有一篇文章:

First, let’s add the jetty plugin to our dependencies. Open the tab Dependencies in your plugin configuration. Then add these six plugins to the Required Plug-ins:

javax.servlet
org.eclipse.equinox.http.jetty
org.eclipse.equinox.http.regstry
org.eclipse.equinox.http.servlet
org.mortbay.jetty.server
org.mortbay.jetty.util

In the list of plugins included at the launch of application you need to change the Auto-Start value for three plugins to true (if you are lazy, you can turn the default behavior to auto start but this is another concern):

org.eclipse.equinox.http.jetty
org.eclipse.equinox.http.regstry
org.eclipse.equinox.http.servlet

Now if you run the application you can check if your server is correctly running by accessing http://localhost. This should work flawlessly except maybe if you are not allowed to run server in port 80 or there is already a server running in port 80.

You can change the port by adding an argument to the VM arguments in Run Configurations. Add this value: -Dorg.eclipse.equinox.http.jetty.http.port=8888. Change 8888 to whatever port you want the server to be running.

Now if you are running the application, you can access it from the port you mentioned before.

The next task is to define one (or several) servlet(s) that will serve any request the server gets. To do this, you need to open the Extensions tab from your plugin configuration and add a new extension named org.eclipse.equinox.http.registry.servlets. After that add new servlet. You need to mention the class name of the servlet, and an alias for that. One note here is you need to add slash in front of the alias. For example, if you want to make the servlet accessible from http://localhost:8888/webserviceInterface, then the alias value is /webserviceInterface. Of course, you need to implement a servlet which will do the work you want.