简体   繁体   中英

Deploy Struts2 WebApp Within An Eclipse RCP Application Via Jetty

Now here's a mess for you...

I am currently working on an Eclipse RCP application plugin. The goal of this plugin is to serve up a webapp for users to interact with within an Eclipse ViewPart (SWT browser control).

I would like for this webapp to be powered by Struts2 and I already have Jetty at my disposal for serving things up.

Is there any way at all I can deploy a Struts2 WebApp in this way? If more info is needed please ask!

EDIT #1:

Some more detail. The only way I know how to deploy a struts2 application currently is via a war file (hosting on tomcat, that is). This is not something I can do in this case. I need to somehow deploy struts2 internally in an embedded way using the Jetty server provided with the Eclipse RCP framework.

RESULT:

As it turns out you can deploy a WAR file (struts2 app in this case) with embedded Jetty. I found Joakim Erdfelt doing it here: Embedding Jetty as a Servlet Container

Struts2 web application can run in the servlet container like Jetty. Jetty also have an embedded option. Eclipse RCP uses Eclipse platform for extension and customization with plugins. There's an article of 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM