Create a WAR from RAP Application with Libra WAR Product [step3]
In [step2] we have created WAR Product files from RAP launches. In this article we will generate WAR by using the export WAR feature of the WAR Product to generates two WARs:
We will deploy generated WARs in a non OSGi HTTP Server Apache Tomcat. You can see the online demo of the rap-jpa.war created with WAR Product deployed on CloudBees which provides an Apache Tomcat at http://rap-war.opensagres.cloudbees.net/eclipsespring.
We will see in this article that projects of eclipsespring_step10.zip contains 2 problems when WAR will be exported and deployed:
- .qualifier must not used in the Host of fragments.
- pay attention with build.properties of Plug-in /Fragments which must include the whole files (META-INF, fragment.xml, plugin.xml, etc).
Those 2 errors are interesting because it works with RAP launch but not with WAR Product.
You can download eclipse_spring_warproduct.zip which contains the two WAR Products created in this article.
Create WAR rap-jpa.war of « RAP Client – JPA Dao »
In this section we use the features of WAR Product Editor to create the rap-jpa.war WAR. To do that Open the rap-jpa.warproduct with the WAR Product Editor.
Validate WAR product
Before creating WAR, click on Validate WAR product menu item to check you have not problem with Plug-Ins/Fragments of the WAR Product:
Export WAR product
If you have none errors, we can start exporting the WAR. To do that, click on Export WAR product menu item:
This action opens the Export dialog :
- choose the file name of the generated WAR (here we will export WAR to generate the C:\rap-jpa.war).
- select the « Allow for binary cycles in target platform » checkbox.
NOTE: here My WAR Product is used and display a checkbox « Allow for binary cycles in target platform » which is required to fix problem with cycle that we have with Spring.
Click on Finish button which starts the export of the WAR, but it fails with this error:
This error is interesting because this problem doesn’t occur when RAP launch is used. The problem comes from the OSGi Fragment fr.opensagres.dao.jpa.eclipselink
linked to OSGI bundle fr.opensagres.dao.jpa which defines version with .qualifier. The OSGi Fragment fr.opensagres.dao.jpa.eclipselink
uses the .qualifier at this step:
Remove the .qualifier used in the OSGi Fragment fr.opensagres.dao.jpa.eclipselink for Hosts:
Export the WAR, and you will see that rap-jpa.war will be generated with success.
Test WAR rap-jpa.war
At this step we can test our WAR. In my case, I have tested the WAR with Apache Tomcat and follow thoses steps:
- Install Tomcat.
- Copy/paste the rap-jpa.war in the webapps folder of the root of the Tomcat.
- Start the Tomcat on the 8080 port by using the bin/startup.bat (or startup.sh).
Once the HTTP Server has deployed the war, tries to go to the URL http://127.0.0.1:8080/rap-jpa/eclipsespring, but you will have this 404 error:
But if you go at http://127.0.0.1:8080/rap-jpa/rap?startup=fr.opensagres.richclient.application it works:
It means that the eclipsespring servlet that we have defined in the fragment.xml of the bundle fr.opensagres.richclient.config.rap is not used:
<extension point="org.eclipse.rap.ui.branding"> <branding servletName="eclipsespring" themeId="org.eclipse.rap.design.example.business.theme" defaultEntrypointId="fr.opensagres.richclient.application" title="RAP Application" id="fr.opensagres.richclient.branding"> </branding> </extension>
If you unzip the JAR of the rap-jpa/WEB-INF/plugins/fr.opensagres.richclient.config.rap you will see that fragment.xml doesn’t exists. The reason of that
is that build.properties of the fr.opensagres.richclient.config.rap bundle, doesn’t include the fragment.xml.
To resolve this problem, open the MANIFEST-MF of this bundle, go to the Build tab and select fragment.xml :
Rebuild the WAR and deploy it.
URL and branding
As we use the org.eclipse.rap.design.example Plug-In in the WAR Product, we can benefit from branding features of RAP which provides several themes.
Now if you go to the URL http://127.0.0.1:8080/rap-jpa/eclipsespring, you will see:
You can test that with online demo at http://rap-war.opensagres.cloudbees.net/eclipsespring.
if you go to the URL http://127.0.0.1:8080/rap-jpa/rap?startup=fr.opensagres.richclient.application, you will see:
You can test that with online demo at http://rap-war.opensagres.cloudbees.net/rap?startup=fr.opensagres.richclient.application.
if you go to the URL http://127.0.0.1:8080/rap-jpa/fancy?startup=fr.opensagres.richclient.application, you will see:
You can test that with online demo at http://rap-war.opensagres.cloudbees.net/fancy?startup=fr.opensagres.richclient.application.
if you go to the URL http://127.0.0.1:8080/rap-jpa/business?startup=fr.opensagres.richclient.application, you will see:
You can test that with online demo at http://rap-war.opensagres.cloudbees.net/business?startup=fr.opensagres.richclient.application.
Create WAR rap-mock.war of « RAP Client – Mock Dao »
You can generate the rap-mock.war with the rap-mock.warproduct by exporting the WAR like explained below.
With WAR Product, HTTP Server starts the OSGi container. Is it possible to access to the OSGi console? The answer is yes. You must just configure web.xml to tell to the ServletBridge servlet which starts the OSGi container that OSGi console must be available by adding -console in the commandline.
<init-param> <param-name>commandline</param-name> <param-value>-registryMultiLanguage -console -ws rap</param-value> </init-param>
When you will start the bin/startup.bat, you will see some Tomcat logs and OSGi console will be launched too.
In this article we have exported the WAR from WAR Product to generate WAR. We have seen how it’s very easy to generate WAR from RAP launches.