Of course, the Virgo Programmers manual covers a lot of the steps nessecary. My emphasis lies on Snaps and ease of development, so lets start:
First of all, you should install the Spring Virgo Tooling from http://dist.springsource.com/release/TOOLS/update/e3.6. After that you should be able to start your installed Virgo Server from within Eclipse following the instructions from the Virgo Programmers Manual.
My first Web application bundle!
Create an Eclipse RT bundle project:
Name it org.test.host. Besides the required project natures, only one file is created: The Manifest. Open it and, in the MANIFEST.MF editor, add the following line:
Web-ContextPath: /test
Then create an index.jsp file in the src-folder with any (simple) content you like, e.g. "hello, world".
Believe it or not, but you have just created your first web application bundle, an artifact that is an OSGi-bundle as well as a web application.
Now in the Server View, in the popup-menu of your Virgo server, choose add and remove to add the new bundle to your server (of course you could also build a jar and copy it to the pickup area). You bundle is listed as available resource. Add it to your server. The console will show how the bundle is started and bound to the context /test. Thus it is not too surprising to get the hello world message on navigating to http://localhost:8080/test/index.jsp.
My first Snap!
Beware! Things may become boring now.
Create another bundle project, just as above, but to the MANIFEST.MF file now add:
Snap-Host: org.test.host;version="[1.0, 2.0)"
Snap-ContextPath: /snap1
Even another src/index.jsp should show some different content. Project layout should now be similar to this:
Congrats, your first snap was born. After adding it to the server, this content is now served under http://localhost:8080/test/snap1/index.jsp.
Note that this snap is not a web application bundle (we did not add the Web-ContextPath header), thus it does not serve http://localhost:8080/snap1/index.jsp.
Integrating snaps
The interesting thing is, the host can be extended by snaps. And that can be done so that the user interface automatically adapts.
Insert the following code in the index.jsp of the host:
To be able to compile this jsp, you need to import some packages into the bundle, namely
After redeploy (because you have changed the manifest, a simple JSP change is automatically hot deployed... great!), on http://localhost:8080/test/index.jsp, you are presented a list - ahem, well, with one item - of all snaps with a link to their respective index.jsp. This way, the application adapts to the current OSGi bundles state.
Note that this snap is not a web application bundle (we did not add the Web-ContextPath header), thus it does not serve http://localhost:8080/snap1/index.jsp.
Integrating snaps
The interesting thing is, the host can be extended by snaps. And that can be done so that the user interface automatically adapts.
Insert the following code in the index.jsp of the host:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="snaps" uri="http://www.springsource.org/dmserver/snaps" %> <html> <head/> <body> <h1>Snaps</h1> <snaps:snaps var="snaps"> <c:forEach var="snap" items="${snaps}"> <li> <a href="<c:url value="${snap.contextPath}/index.jsp"/>"> ${snap.contextPath} </a> </li> </c:forEach> </snaps:snaps> </body>
To be able to compile this jsp, you need to import some packages into the bundle, namely
- com.springsource.org.apache.taglibs.standard;version="[1.1.2,1.1.2]",
- org.eclipse.virgo.snaps.api;version="[0.0.0,2.0.0]",
- com.springsource.javax.servlet.jsp.jstl;version="[1.1.2,1.1.2]"
After redeploy (because you have changed the manifest, a simple JSP change is automatically hot deployed... great!), on http://localhost:8080/test/index.jsp, you are presented a list - ahem, well, with one item - of all snaps with a link to their respective index.jsp. This way, the application adapts to the current OSGi bundles state.
Hi,
thanks for this tutorial, it was very helpful. However again I had some issues. Maybe this is due to the fact I'm using different version of both Snaps and Eclipse Virgo. Can you specify which versions you are using?
Some of my differences were:
* Snaps prefix should be defined as: <%@ taglib uri="http://www.eclipse.org/virgo/snaps" prefix="snaps" %>
* I needed the following import in my manifest file: Import-Package: org.eclipse.virgo.snaps.core;version="1.0" Otherwise, the app didn't run.
Nevertheless thanks for your input, it was really, really helpful.
Cheers,
Andrzej
Hi,
I'm evaluation Virgo snaps for a new project and I managed to have the snaps test application running fine on Virgo server. I use the latest git source and compile the Virgo web (org.eclipse.virgo.web) and org.eclipse.virgo.snaps. I can access the simple-host web application and then I can add simple-snap bundle and see the OK result.
But I can't find a way to integrate Virgo with Eclipse. I installed the SpringSource server tools. I added the Virgo server, but when I try to publish the simple-host to Virgo server (using Eclipse), the "stage" folder is not completely populated with files from simple-host project. The Eclipse publisher is creating simple-host.jar folder and inside there is an empty WEB-INF folder and a META-INF folder with an empty MANIFES.MF file.
Hi,
Thanks for this tutorial!
Besides what Andrzej said, the content of the web.xml was not explained. For me it was necessary to add a host-filter there.
See also: http://blog.springsource.com/2009/06/22/modular-web-applications-with-springsource-slices/ - Section "Inside the Host", elements filter and filter-mapping, but with filter-class org.eclipse.virgo.snaps.core.SnapHostFilter (instead of slices)
Best regards,
Boato