This part is about deploying a RAP application in a .war file. In Part 1 we explored how to deploy a RAP application with Jetty.
Part 2: Deploying a Servlet Bridge .war on an Existing Server
In this part we will create a .war file containing our application, its dependencies, RAP, Equinox and the Servlet Bridge. This allows us to run Equinox (and our application) in a servlet container. The Servlet Bridge plays a central part behind the covers, as it allows the RAP Runtime to handle the HTTP requests originally sent to the application server.
To create the .war file we start with a working example (the org.eclipse.rap.demo.feature from the Eclipse CVS) and create a copy of it (the calc.ui.war.feature). We then follow the WAR Deployment instructions from the RAP Help to produce a .war for the calculator application.
The .war file can then be uploaded to a regular app server -- I used Tomcat in the screencast.
Watch the screencast (approx. 11 minutes) or read on for more details.
Below are the steps shown in the screencast. You can download the finished example here (just after step 9). This a different download than the one from part 1!
- Start with a working example by checking out the org.eclipse.rap.demo.feature from the Eclipse CVS.
Step-by-step instructions:- Copy this string: :pserver:anonymous@dev.eclipse.org:/cvsroot/technology
- Open the CVS Repositories View.
- Right click > Paste Connection.
- Expand the nodes ":pserver...", "HEAD" and "org.eclipse.rap" in the tree. Select org.eclipse.rap.demo.feature and choose "Check Out".
- You should now have org.eclipse.rap.demo.feature in your workspace.
- Copy this string: :pserver:anonymous@dev.eclipse.org:/cvsroot/technology
- Obtain the servlet bridge.
Open the URL below in your Browser and save the contents: http://www.eclipse.org/equinox/server/downloads/servletbridge-anon.psf
Then use the Team Project Set import wizard to add the projects to your workspace (File > Import > Team Project Set > enter the path to the file you saved > Finish). You should now have these additional projects in your workspace:- javax.servlet (v2_4)
- org.eclipse.equinox.http.registry
- org.eclipse.equinox.http.servlet
- org.eclipse.equinox.http.servletbridge
- org.eclipse.equinox.servletbridge
- org.eclipse.equinox.servletbridge.feature
- Import the org.eclipse.update.configurator plug-in from your eclipse installation (not the target!).
Choose File > Import > Plug-ins and Fragments. In the "Import From" group uncheck the option "The target platform (as specified in the Preferences"). Under "Plug-in Location" enter the path to your plugins directory (for example: c:\temp\eclipse\plugins). Next. Select org.eclipse.update .configurator. Add. Finish. - Make a copy of the org.eclipse.rap.demo.feature and name it calc.ui.war.feature
- Adjust the copied feature.xml.
Change the id to "calc.ui.war.feature". Change the fields Version, Name and Provider to your liking. Then modify the list of Plug-ins and Fragments: remove org.eclipse.rap.demo; add calc.ui.rap. Save.
(Alternatively you can start with an empty list of plug-ins and add: calc.ui.rap and all its dependencies using the Dependency Analysis tool as shown in Part 1. Then add org.eclipse.update.configurator (for auto-discovery of bundles). Then add the org.eclipse.equinox.http.servlet and org.eclipse.equinox.http.servletbridge. At the end you should have 20 plugins in the feature) - Adjust the copied ant script under script\webappBuilder.xml.
- Change the servletbridge.dir property to point to the absolute location of the org.eclipse.equinox.servletbridge plugin on your machine. Remember to use '/' as the path delimiter.
- Change the features property to "calc.ui.war.feature". This determines which feature the script will export.
- Save.
- Configure and run the ant task.
- Select webappBuilder.xml and open the External Tools Dialog (Run > External Tools > Open External Tools Dialog).
- Double click on "Ant Build".
- Select the new entry (calc.ui.war.feature webappBuilder.xml).
- In the JRE Tab adjust "Runtime JRE" to "Run in the same JRE as the workspace" (otherwise the script will not be able to use the PDE Ant Task for exporting our feature).
- Run.
- You should see a "BUILD SUCCESSFUL" message on the console. Notice that the PDE Export task is still running in the background (progress indicator). Wait until it finishes.
- Select the calc.ui.war.feature and hit Refresh (F5).
You should now have a build directory in that project with the following content:- build\rapdemo\WEB-INF\eclipse\configuration
- build\rapdemo\WEB-INF\eclipse\features
- build\rapdemo\WEB-INF\eclipse\plugins
- build\rapdemo\WEB-INF\eclipse\.eclipseproduct
- build\rapdemo\WEB-INF\eclipse\launch.ini
- build\rapdemo\WEB-INF\lib\servletbridge.jar
- build\rapdemo\WEB-INF\web.xml
- Open the Equinox config.ini file (in build\rapdemo\WEB-INF\eclipse\configuration). Check that the osgi.bundles attribute has these values:
osgi.bundles=org.eclipse.equinox.common@2:start, org.eclipse.update.configurator@start, org.eclipse.equinox.http.servletbridge@start, org.eclipse.equinox.http.registry@start
At this point I skipped the "Adjust the config.ini" file section in the RAP WAR Deployment instructions. From my understanding this is not necessary if the org.eclipse.update.configurator plug-in is part of the .war, since it will auto-discover the other plug-ins. However we need to start the above plug-ins when launching to "bootstrap" our application. - Zip the whole WEB-INF directory into a .war file, for example calc.war. Make sure that WEB-INF is included in the archive, like shown in this example:
C:\temp\workspace\calc.ui.rap.war.feature\build\rapdemo>unzip -l calc.war | head
Archive: calc.war
Length Date Time Name
-------- ---- ---- ----
0 12-06-07 15:32 WEB-INF/
0 12-06-07 15:32 WEB-INF/eclipse/
0 12-06-07 15:32 WEB-INF/eclipse/.eclipseproduct
[...] - Deploy calc.war on your webserver. In my example I used the Manager Webapp that comes with Tomcat.
- Go to http://yourserver:yourport/calc/rap in your browser. Assuming everything went smoothly you should see the calculator application.
- Troubleshooting: If you don not see the calculator go to the shell that is running tomcat. Here you should see an "osgi>" prompt. This is the osgi console. Type "ss". If you have unresolved (=INSTALLED) bundles, you missed some dependencies. Also check the .log file under tomcat\work\Catalina\localhost\calc\eclipse\workspace\.metadata. If you see something other than "Authorization infrastructure (org.eclipse.core.runtime.compatibility.auth) not installed" you probably missed some dependencies. In my case I ignored the aforementioned message because I don't need that optional plug-in in my deployment.
Important Note: For production deployments I recommend disabling the osgi console. For example if you type "exit" on it, you'll bring down the whole app server :-P. The command line arguments for our app are defined in the file templates\WEB-INF\web.xml. Remove or comment out the following lines:
<init-param>
<param-name>commandline</param-name>
<param-value>-console</param-value>
</init-param>
17 comments:
Hi Alias.
Thanks for the tuorial.
I have tried to deploy my app without success. I am able to start OSGI (as I cam able to type ss in the console and see the status of bundles ) but not able to run the app in the browser. How does one specify which port? Is the Equinox launcher neccessary for deployment? Should org.eclipse.rap.demo pluin be included in the feature? If you could shed more light on the whole deployment process I'd much appreciate it.
Thanks, Anon
Joining the question.
I was able to deploy the finished example you gave, but couldn't make one myself.
I'm working with Eclipse 3.3 J2EE configuration with the RAP plugin.
I'm totally new to RAP/RCP development, so if you could give more details that would be great.
Anyway thank you for this tutorial.
Hi
Joining the question.
I was able to deploy the finished example you gave, but couldn't make one myself.
I'm totally new to RCP/RAP development so if you can give more details that would be great.
I'm using Eclipse 3.3 J2EE configuration with the RAP plugin.
Thank You.
Hi,
I followed the video and created the WAR file. No problem.
I tried to deploy on Tomcat and I have this error in Tomcat log file
--------------------------------
org.apache.catalina.loader.StandardClassLoader@da18ac
----- GRAVE: Error loading WebappClassLoader
delegate: false
repositories:
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@995a79
org.eclipse.equinox.servletbridge.BridgeServlet
java.lang.ClassNotFoundException: org.eclipse.equinox.servletbridge.BridgeServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1362)
--------------------------------
WEB-INF\lib\servletbridge.jar
is well in my WAR file.
I have no problem with rapdemo.war
Thanks
Olivier
Hi
first of all, nice work. Thanks a lot.
to the question of anonymous, I had the same problem.
Check the content of the servletbridge.jar, the class should be there. My mistake was in the webappBuilder.xml. I added the path to org.eclipse.equinox.http.servletbridge, the correct value should be without .http
regards Marius
Hi -
I also appreciate your screencast - nice work. I'd like to see RAP become an alternative for my customers in the future as it is very interesting technology.
I tried to deploy to WebSphere 6.1 and had some difficulty. Has anyone deployed to this environment? My error message is "BundleException: The activator ...http.servletbridge.internal.Activator for bundle ...http.servletbridge is invalid". The reason stated is "The type javax.servlet.http.HttpServlet cannot be resolved."
It seems odd to me that this very standard interface would not be resolved.
Any ideas? Is this because WebSphere in version 6.1 is also an osgi implementation? I do not see any equinox plugins with the application server, but I do see org.eclipse.osgi_3.1.2.jar and org.eclipse.core.runtime_3.1.2.jar among others in the application server plugins directory.
I wonder if my error is because the version of eclipse core and osgi is 3.1? The documentation suggests a version of equinox being either 3.2 or 3.3.
Any ideas are greatly appreciated.
Thanks, Alden
Hi Alden,
unfortunately I do not have a Websphere installation available, so I can't help you.
Try to ask this on the RAP Newsgroup...
Regards,
Elias.
Hi Elias,
Thank you for the tutorial.
Have you tried to deploy it under Linux ? I can't find OSGI console when deploying under Linux.
Hi setya,
normally you should have the OSGi console once you add "-console" to the launch config.
For the deployed version check that you have this snippet in the web.xml file:
<!-- this goes into the servlet-node -->
<init-param>
<param-name>commandline</param-name>> <param-value>-console</param-value>
</init-param>
You can find the full example by checking out /org.eclipse.rap.demo.feature/templates/WEB-INF/web.xml from CVS.
AFAIK, it should work under linux too.
Hope this helps,
Elias.
Hi Elias,
On Linux, Tomcat does not open 2nd console as in Windows, this 2nd console is in fact the OSGI console. You have to manually open 2nd console and invoke command tail -f catalina.out.
Also when I deploy on Linux Tomcat keeps throwing words 'OSGI>' in its catalina.out until I shutdown. I firstly did not realize this until suddenly the catalina.out grew up to 1.3GB.
The problem above was asked here :
http://dev.eclipse.org/newslists/news.eclipse.technology.rap/msg01422.html
On Windows, when I deploy the calculator example I can use the OSGI console but not all bundles are automatically activated. I have to activate them manually using 'start' command. But when I try to activate org.eclipse.equinox.servletbridge.extensionbundle_1.0.0 it throws :
org.osgi.framework.BundleException: A fragment bundle cannot be started: update@plugins/org.eclipse.
equinox.servletbridge.extensionbundle_1.0.0.jar [18]
at org.eclipse.osgi.framework.internal.core.BundleFragment.startWorker(BundleFragment.java:2
24)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:260)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:252)
at org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._start(FrameworkCommand
Provider.java:260)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.execute(FrameworkCom
mandInterpreter.java:145)
at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(FrameworkConsole.java
:291)
at org.eclipse.osgi.framework.internal.core.FrameworkConsole.console(FrameworkConsole.java:2
76)
at org.eclipse.osgi.framework.internal.core.FrameworkConsole.run(FrameworkConsole.java:218)
at java.lang.Thread.run(Unknown Source)
Thanks,
Setya
Hi,
Despite the aforementioned problems I have successfully deployed the application.
BTW, is suffix /rap an absolute requirement to access the RAP application ?
Thanks,
Setya
Hi Setya,
great to hear you were successful.
The /rap suffix can be changed to anything you like. Refer to the help on RAP Branding for details.
Regards,
Elias.
hi,
thx for the tut.
ive dont the same steps like you but my tomcat throws this error:
HTTP Status 404 - BridgeServlet: /calc/rap
can anyone help me ?
which tomcat version did you use ?
greets
Hi Anonymous,
I've used Tomcat 5.5.25 and 5.5.26.
I haven't tried tomcat 6.x but according to this thread on the newsgroup, there have been some problems (similar to yours) with it.
Hope this helps,
Elias.
I was getting Http error -404.later I realized my mistake.I was creating the war file not from some other directory which caused including some other unnecessary files in war.Thats why my webapp manager was not properly deploying the war file.When I did from the directory just above the WEB-INF,it worked perfectly fine
Thanks much for the tutorial. I am new to RAP and wondering whether or not it is worth investing time in. For example, my current RCP app use JFreeChart SWT graphics, I have no clue how RAP would implement these in an RIA?
Hi anonymous,
JFree can be used with RAP, if you write a servlet that returns the chart as an image. Refer to the following threads in the Eclipse RAP newsgroup:
* Charts in RAP
* Jfree
Regards,
Elias.
Post a Comment