gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 07:58:13 25 4
gpt4 key购买 nike

现在这对你来说是一团糟......

我目前正在开发 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.

关于java - 通过 Jetty 在 Eclipse RCP 应用程序中部署 Struts2 WebApp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32341030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com