Blogs

SpringSource Blog

SpringSource Application Platform Deployment Options

Sam Brannen

Since we released the SpringSource Application Platform last Wednesday, numerous developers have downloaded the 1.0.0 beta and started taking the Platform for a test drive. As a result, people have begun asking, "How can I deploy my apps on the Platform, and what kind of deployment and packaging options do I have?" Moreover, developers are eagerly requesting to see working samples. In response, the S2AP team will be releasing several sample applications over the coming weeks demonstrating these features and more, but before you get your hands on these samples, I'd like to give you a high-level overview of the deployment and packaging options available in the Platform. After reading this post you'll be ready to hit the ground running with the samples as well as with your own applications.

Overview

As Rob mentioned in his post last week, Introducing the SpringSource Application Platform, the Platform supports applications packaged in the following forms:

  1. Raw OSGi Bundles
  2. Java EE WAR
  3. Web Modules
  4. Platform Archive (PAR)

When you deploy an application to the Platform, each deployment artifact (e.g., a single bundle, WAR, or PAR) passes through a deployment pipeline. This deployment pipeline supports the notion of personality-specific deployers which are responsible for processing an application with a certain personality (i.e., application type). The 1.0.0 release of the Platform natively supports personality-specific deployers analogous to each of the aforementioned packaging options. Furthermore, the deployment pipeline can be extended with additional personality deployers, and future releases of the Platform will provide support for personalities such as Batch, Web Services, etc.

Let's take a closer look now at each of the supported deployment and packaging options to explore which one is best suited for your applications.

Raw OSGi Bundles

At its core, the SpringSource Application Platform is an OSGi container. Thus any OSGi-compliant bundle can be deployed directly on the Platform unmodified. You'll typically deploy an application as a single bundle or a set of stand-alone bundles if you'd like to publish or consume services globally within the container via the OSGi Service Registry. Please note, however, that due to the scoping nature of the PAR format, stand-alone bundles will not be able to consume services across application boundaries. In other words, a stand-alone bundle can not reference the services of modules deployed within a PAR.

WAR Deployment Options

For Web Application Archives (WAR), the SpringSource Application Platform provides support for the following three formats.

  1. Standard Java EE WAR
  2. Shared Libraries WAR
  3. Shared Services WAR

Each of these formats plays a distinct role in the incremental migration path from a standard Java EE WAR to an OSGi-ified web application.

Standard WAR

As Rob has already pointed out, "Standard WAR files are supported directly in the Platform. At deployment time, the WAR file is transformed into an OSGi bundle and installed into Tomcat. All the standard WAR contracts are honoured, and your existing WAR files should just drop in and deploy without change." Support for standard, unmodified WAR files allows you to try out the SpringSource Application Platform on your existing web applications and then gradually migrate toward the Shared Libraries WAR, Shared Services WAR, and Web Module formats.

Shared Libraries WAR

If you have experience with developing and packaging web applications using the standard WAR format, you're certainly familiar with the pains of library bloat. So, unless you're installing shared libraries in a common library folder for your Servlet container, you have to pack all JARs required by your web application in /WEB-INF/lib. Prior to the release of the Platform, such library bloat has essentially been the norm for web applications, but now there is a better solution! The Shared Libraries WAR format reduces your application's deployment footprint and eradicates library bloat by allowing you to declare dependencies on libraries via standard OSGi manifest headers such as Import-Package and Require-Bundle. The Platform provides additional support for simplifying dependency management via the Import-Library and Import-Bundle manifest headers which are essentially macros that get expanded into OSGi-compliant Import-Package statements.

For detailed information on what kind of libraries you already have at your disposal, check out the SpringSource Enterprise Bundle Repository. In addition, Andy Wilkinson will be posting a blog later this week explaining how to make the most of the Bundle Repository within your applications and the SpringSource Application Platform. So stay tuned.

Shared Services WAR

Once you've begun taking advantage of declarative dependency management with a Shared Libraries WAR, you'll likely find yourself wanting to take the next step toward reaping further benefits of an OSGi container: sharing services between your OSGi-compliant bundles and your web applications. By building on the power and simplicity of Spring-DM, the Shared Services WAR format puts the OSGi Service Registry at your fingertips. As a best practice you'll typically publish services from your domain, service, and infrastructure bundles via <osgi:service … /> and then consume them in your web application's ApplicationContext via <osgi:reference … />. Doing so promotes programming to interfaces and allows you to completely decouple your web-specific deployment artifacts from your domain model, service layer, etc., and that's certainly a step in the right direction. Of the three supported WAR deployment formats, the Shared Services WAR is by far the most attractive in terms of modularity and reduced overall footprint of your web applications.

Web Modules

Above and beyond WAR-based deployment formats, the SpringSource Application Platform introduces a deployment and packaging option for OSGi-compliant web applications, the Web Module format. Web modules have a structure similar to a Shared Services WAR and can therefore take full advantage of all three WAR deployment formats. In addition, web modules benefit from reduced configuration for Spring MVC based applications via new OSGi manifest headers such as Web-DispatcherServletUrlPatterns and Web-FilterMappings. For further details on these and other Web-* manifest headers, please consult the Platform's Programmer Guide. Upcoming releases of the Platform will also support web.xml fragments as well as the aforementioned manifest headers.

If you're building a Spring MVC based web application as a web module, you won't need to worry about configuring a root WebApplicationContext or an ApplicationContext for your DispatcherServlet. Based on metadata in your web module's /META-INF/MANIFEST.MF, the Platform will auto-generate an appropriately configured web.xml for you on-the-fly, and your application will use the ApplicationContext created for your web module by Spring-DM. Future releases will add additional support to simplify configuration of Spring Web Flow based web applications as well.

Migration path from WAR to Web Module

The following diagram graphically depicts the migration path from a Standard WAR to a Web Module. As you can see, the libs move from within the deployment artifact to the Bundle Repository. Similarly, the services move from within the WAR to external bundles and are accessed via the OSGi Service Registry. In addition, the overall footprint of the deployment artifact decreases as you move towards a Web Module.

Migration path from WAR to Web Module

Platform Archives

The final piece of the puzzle is the PAR (Platform Archive) deployment format. A PAR is a standard JAR which contains all of the modules of your application (e.g., service, domain, and infrastructure bundles as well as a WAR or web module for web applications) in a single deployment unit. This allows you to deploy, refresh, and undeploy your entire application as a single entity. For those of you familiar with Java EE, a PAR can be considered a replacement for an EAR (Enterprise Archive) within the context of an OSGi container. As an added bonus, modules within a PAR can be refreshed independently and on-the-fly, for example via the SpringSource Application Platform Tool Suite (register for the beta program and check out the Eclipse tooling support).

Furthermore, PARs scope the modules of your application within the Platform. Scoping provides both a physical and logical application boundary, shielding the internals of your application from any other applications deployed within the Platform. This means your application doesn't have to worry about clashing with other running applications (e.g., in the OSGi Service Registry). You get support for load-time weaving, classpath scanning, context class loading, etc., and the Platform does the heavy lifting for you to make all this work seamlessly in an OSGi environment. If you want to take full advantage of all that the SpringSource Application Platform and OSGi have to offer, packaging and deploying your applications as a PAR is definitely the recommend choice.

Where to go from here

If you haven't already done so, I encourage you to join the beta program and take the SpringSource Application Platform for a test drive yourself.

You'll find up-to-date documentation in the user guide and programmer guide, and if you happen to run into any issues deploying your applications or have recommendations on how we can improve the Platform, please don't hesitate to create a JIRA issue.

And last but not least, be sure to check out upcoming posts on the SpringSource Team Blog to keep abreast of news regarding the Platform and to see working examples including an OSGi-ified Spring PetClinic sample application which has been modularized and packaged as a PAR.

Similar Posts

Share this Post
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • DZone
  • LinkedIn
  • Slashdot
  • Technorati
  • Twitter
 

22 responses


  1. Hello Sam,

    does that mean that I cannot actually export services to the OSGi service registry from within a PAR-packaged application? Or more precisely, how does "shielding the internals of your application from any other applications deployed within the Platform" limit a PARs ability to interact (via OSGi) with other modules deployed into the same Platform instance?

    Thank you,

    Nils


  2. Hi Nils,

    That's a good question.

    [quote comment="105514"] does that mean that I cannot actually export services to the OSGi service registry from within a PAR-packaged application? [/quote]

    No, you can still export services to the OSGi Service Registry from modules within your PAR.

    [quote comment="105514"] Or more precisely, how does "shielding the internals of your application from any other applications deployed within the Platform" limit a PARs ability to interact (via OSGi) with other modules deployed into the same Platform instance? [/quote]

    The shielding of internals I mentioned does not limit the ability of modules within a PAR to interact with services published in the OSGi Service Registry. I think a more detailed explanation of scoping may help to shed some light on the subject.

    Scoping of modules within a PAR applies to both the types imported and exported by the modules as well as the services they publish and consume via the OSGi Service Registry. Specifically, scoping of services is implemented by auto-generated service properties and matching filters. These effectively only apply to services which are both published and consumed within the PAR. Thus, if you consume a service which is not published within your PAR, the service look-up will not get filtered, and you will get a reference to a service outside your PAR. If you publish a service which is not consumed within your PAR, the service will still be augmented with scoped service properties, but as long as the consumer does not apply a conflicting filter, the consumer will still see the service.

    Regards,

    Sam


  3. Hello again,

    thanks a lot for the clarification. That sounds really neat. Is it possible to publish a service from inside a PAR for both internal and external consumption (i.e. can I override the default filtering)?

    So many questions :)

    Later,

    Nils


  4. [quote comment="105598"]thanks a lot for the clarification.[/quote]

    You're welcome.

    [quote comment="105598"]Is it possible to publish a service from inside a PAR for both internal and external consumption?[/quote]

    Yes, you can publish a service from inside a PAR and reference it internally. This will happen automatically within a PAR, since both the publishing and consumption of services (i.e., via Spring-DM's <osgi:service … /> and <osgi:reference … />, respectively) are scoped. You can also reference the published service externally from outside the PAR, but remember that you'll need to avoid creating a conflicting filter when looking up the service in the OSGi Service Registry.

    [quote comment="105598"]can I override the default filtering?[/quote]

    No, there is currently no way to override the default filtering or service properties applied during scoping.

    However, we are looking into ways to improve this.

    [quote comment="105598"]So many questions :) [/quote]

    Keep 'em coming! ;)

    – Sam


  5. Sam,

    great series of blog entries about S2AP. Keep 'em coming!

    Now that you guys have released PAR version of Petclinic, I would be very interested seeing other deployment versions of it e.g. Shared Libs WAR, Shared Services WAR, Web Module. What are the chances of having these versions of Petclinic available?

    Also I would love to see you guys releasing the Ivy-Ant build system with some docs!

    Thanks,
    Dmitriy.


  6. Another question: is it really a good idea of having services published by modules within PARs (intended by "internal" consumption) be visible from outside PARs (via OSGi registry). Is there any way to prevent that?

    Thanks,
    Dmitriy.


  7. Hi Dmitriy,

    [quote comment="105680"]Now that you guys have released PAR version of Petclinic, I would be very interested seeing other deployment versions of it e.g. Shared Libs WAR,
    Shared Services WAR, Web Module.[/quote]

    FYI: the PetClinic sample application that we recently released already demonstrates a PAR with several bundles (i.e., domain, infrastructure, and repository) as well as a web module.

    [quote comment="105680"]What are the chances of having these versions of Petclinic available?[/quote]

    Due to the complexity of the PetClinic sample application, we are currently only planning on providing the "PAR with a Web Module" deployment version of PetClinic; however, I have some good news for you…

    Colin Yates and I have been working on a migration guide that will walk you through the steps of migrating the Spring 2.0 Form Tags show case application from a Standard Java EE WAR to a Shared Libraries WAR, a Shared Services WAR, and finally a full blown PAR with a Web Module. We'll be providing working examples that you can download, and Colin is
    adding further documentation in a new case study chapter of the Programmer Guide.

    So, with those samples and the documentation in your hands, we're confident that you'll be able to morph the PetClinic sample application into the various deployment formats on your own!

    Regards,

    Sam


  8. [quote comment="105681"]Another question: is it really a good idea of having services published by modules within PARs (intended by "internal" consumption) be visible from outside PARs (via OSGi registry). Is there any way to prevent that?[/quote]

    Those are certainly valid questions, and you're right: ideally you would want to be able to explicitly restrict the visibility of services published and consumed within a PAR so that external bundles could not see those services. There is currently, however, no way to restrict the visibility of services on the Platform other than what scoping provides you.

    Security and visibility of services as well as types are topics that we will be addressing in the Platform over the coming months. So stay tuned and feel free to make suggestions on JIRA.

    Thanks,

    Sam


  9. [quote comment="105696"]

    Colin Yates and I have been working on a migration guide that will walk you through the steps of migrating the Spring 2.0 Form Tags show case application from a Standard Java EE WAR to a Shared Libraries WAR, a Shared Services WAR, and finally a full blown PAR with a Web Module. We'll be providing working examples that you can download, and Colin is
    adding further documentation in a new case study chapter of the Programmer Guide.

    So, with those samples and the documentation in your hands, we're confident that you'll be able to morph the PetClinic sample application into the various deployment formats on your own!

    Regards,

    Sam[/quote]

    That's good news. Thanks Sam.

    Dmitriy.


  10. [quote comment="105698"]

    Security and visibility of services as well as types are topics that we will be addressing in the Platform over the coming months. So stay tuned and feel free to make suggestions on JIRA.

    Thanks,

    Sam[/quote]

    Sounds good to me.

    Dmitriy.


  11. Hi Sam,

    Do the deployment model support update a PART of an application in runtime?

    For example we can deploy the repository layer of PetClinic example as a separated module (not in a PAR) let say for bug fixing.

    I think we also need to take care about module's versions also

    Regards,
    Huy


  12. Hi Huy,

    [quote comment="115153"]Do the deployment model support update a PART of an application in runtime?[/quote]

    Yes, the S2AP supports the ability to refresh a deployed bundle. This support is provided via the Deployer API which is accessible via an MBean (e.g., using JConsole). Note that the SpringSource Application Platform Tools for Eclipse make direct use of this mechanism to refresh your modules as you develop.

    [quote comment="115153"]For example we can deploy the repository layer of PetClinic example as a separated module (not in a PAR) let say for bug fixing.[/quote]

    For the PetClinic sample application, you wouldn't want to pull out the repository layer as that would remove the benefits of the PAR format (i.e., application scoping, context classloading, load-time weaving, etc. within the boundaries of the PAR). You could, however, use the Deployer MBean to refresh a module within the PAR.

    As I mentioned above, the S2AP Tools are great for refreshing modules during development. For production systems, however, direct use of the Deployer MBean may not be as attractive. Thus, future releases of the Platform will provide additional support for refreshing arbitrary bundles at runtime.

    Regards,

    Sam


  13. Hello Sam,
    I have participated in Seminar on e-finance in London on 10 Oct 2008. Could you please share the source code for the demo you presented for 'Standard WAR', 'Shared Library WAR' and 'Shared Service WAR'. This will help me getting hand's on with this.

    Thanks and Regards,
    Rahul


  14. Hi Rahul,

    I haven't yet made the "hello" demos I used at Spring in Finance eXchange available for download; however, if you visit the SpringSource dm Server community page (see link below), you can download the Form Tags sample application which also walks you through the migration process from a standard Java EE WAR all the way to a Web Module within a PAR.

    Links to sample applications: http://www.springframework.org/dmserver

    In addition, the migration process is described in detail in chapter 7 of the Programmer Guide. You can read more about that here:

    http://static.springsource.com/projects/dm-server/1.0.x/programmer-guide/htmlsingle/programmer-guide.html#formtags-case-study

    Hope this helps!

    Sam


  15. Hello sam,

    Thanks for the information and the links. I will surely jump into those sample applications.

    Thanks and Regards,
    Rahul


  16. Hello Sam,

    As suggested by you, I studied the sample formstag source code. It was exactly I was looking for.
    Then I installed eclipse and updated it with Spring IDE through update manager. I also successfully installed and configured Spring dm server, but Spring IDE doesn't seems tobe very conventional IDE's like Netbeans/IntelliJ Idea. I jsut wanted to create 'HelloWorld' spring enabled web application, but under new project I couldn't find any j2ee web application option. There is option called 'Spring Project' but it didn't do much. I tried many other types of project but I didn't create a basic web application skeletion as I expect IDE to do it. Am I missing something?

    I searched the fourums and realised that many people are facing the same problem. Could you please suggest a right way to go about it. If there are any step-by-step tutorial then that would also help.

    Thanks and Regards,
    Rahul


  17. Hi Rahul,

    > As suggested by you, I studied the sample formstag source code. It was
    > exactly I was looking for.

    Great! I'm glad that's working out for you.

    > Then I installed eclipse and updated it with Spring IDE through update
    > manager. I also successfully installed and configured Spring dm server,
    > but Spring IDE doesn't seems tobe very conventional IDE's like
    > Netbeans/IntelliJ Idea. I jsut wanted to create 'HelloWorld' spring
    > enabled web application, but under new project I couldn't find any j2ee
    > web application option. There is option called 'Spring Project' but it
    > didn't do much. I tried many other types of project but I didn't create
    > a basic web application skeletion as I expect IDE to do it. Am I missing
    > something?

    Yes, let me try to provide you an overview of the big picture for tooling support: Spring IDE is a set of plug-ins which build upon the Eclipse IDE and add support for Spring applications. The support for working with web applications is provided by the Eclipse WTP project (i.e., the Web Tools Platform). The SpringSource Tool Suite dm Server Tools are Eclipse plug-ins which support working with OSGi bundles, PAR applications, the local bundle repository for the dm Server as well as WTP Server integration for starting and stopping the dm Server and deploying applications to the server.

    To create a 'HelloWorld' spring enabled web application, you'll need to use the Web / Dynamic Web Project wizard provided with WTP. I personally recommend naming the "Content Directory" src/main/webapp and the "Java Source Directory" /src/main/java, since these paths will work well with build tools like Maven. After you've created the web project, you can add the Spring project nature to it by right-clicking on the project folder and selecting Spring Tools / Add Spring Project Nature.

    The above process will result in a Spring-enabled standard Java EE WAR. If you'd like to convert it to a Shared Libraries WAR or a Shared Services WAR, you should right-click on the project and then select Spring Tools / Add OSGi Bundle Project Nature. This will enable you to use the Bundle Manifest Editor when editing src/main/webapp/META-INF/MANIFEST.MF. Your web project will also now be able to use the manifest classpath container.

    To create a Web Module, you should create a new project using the SpringSource dm Server / Bundle Project wizard. You will then need to create the MODULE-INF and META-INF directories in a path which is configured to be on the Eclipse project's classpath. I recommend placing MODULE-INF and META-INF in src/main/resources.

    > I searched the fourums and realised that many people are facing the same
    > problem. Could you please suggest a right way to go about it.

    If you are unfamiliar with any of the terms or concepts I mentioned above, I recommend you consult the following resources:

    1) Tooling chapter of the dm Server Programmer Guide:
    http://static.springsource.com/projects/dm-server/1.0.x/programmer-guide/htmlsingle/programmer-guide.html#tooling

    2) Eclipse WTP: http://www.eclipse.org/webtools/

    > If there are any step-by-step tutorial then that would also help.

    At the moment, there isn't a step-by-step tutorial per se which demonstrates exactly how to create web applications for the dm Server using the STS dm Server Tools, but this is certainly something we are considering adding to the Programmer Guide.

    Regards,

    Sam


  18. Hello Sam,

    Thanks for your time helping me with this problem. The clarification is very neat. I will follow the steps you suggested. Looking forward to give you a good news for successful development and deployemnt of sample application with Spring IDE.

    Your response was really quick !Thanks Sam !

    Cheers,
    Rahul


  19. Hello Sam,

    Here is small update on my proceedings. I could managed to develope and deploy the follwoing types of web-applications with Spring IDE and dm server.
    1. Conventional WAR
    2. Spring Enabled WAR.
    3. Spring Enabled Shared Library War.
    4. Only the bundle for Shared service.

    Now I am looking forwad for Shared Service WAR. Please verify my understanding about this concept.
    1. Shared Service is actually a bundle which exposes its operation throgh interface. We need to export this interfaces and domain objects through its MANIFEST.MF file so outside world can see it.
    2. To access this service, we need to create a consumer (e.g Web Application) which imports interface and domain objects.

    The problem is that, Even after exporting from bundle MANIFEST and importing into WAR MANIFEST, classes in web application (Controller) can't see imported classes.
    The files module-context.xml and osgi-context.xml in bundle are referenced where and how? or they get automatically detected by dm server and gets registered as OSGI service?

    Once the bundle is deployed, Shall I see it somewhere under <>\repository.

    Thanks and Regards,
    Rahul


  20. Hi Rahul,

    1. Shared Service is actually a bundle which exposes its operation through interface. We need to export this interfaces and domain objects through its MANIFEST.MF file so outside world can see it.

    With regard to types (i.e., classes and interfaces), yes you will need to explicitly export the corresponding packages using Export-Package in the bundle's META-INF/MANIFEST.MF file. This concept, however, is identical to the concept of exporting packages introduced in the Shared Libraries WAR. The difference between the Shared Libraries WAR and the Shared Services WAR is that the latter also makes use of the OSGi Service Registry. Please note that the word "service" in this context has no direct correlation to the notion of a "service" in the "service layer" of your application. In OSGi you can publish any object in the Service Registry.

    2. To access this service, we need to create a consumer (e.g Web Application) which imports interface and domain objects.

    Yes, for the types, that is correct: you would import them via Import-Package statements in your web application's manifest.

    The problem is that, Even after exporting from bundle MANIFEST and importing into WAR MANIFEST, classes in web application (Controller) can't see imported classes.

    This is expected due to how the STS dm Server Tools work with regard to related projects. Bundle Projects can only see the exported types of other Bundle Projects if:

    a) the two projects are configured in the same PAR, or
    b) the importing project has configured a "Project Reference" for the exporting project.

    For details on this, please see the following forum thread:

    http://forum.springframework.org/showthread.php?t=61559

    The files module-context.xml and osgi-context.xml in bundle are referenced where and how? or they get automatically detected by dm server and gets registered as OSGI service?

    Spring-DM will by convention automatically load any *.xml files found in META-INF/spring as Spring ApplicationContext configuration files. To publish a service in the OSGi Service Registry or to consume such a service, you will need to make use of Spring-DM's <osgi:service> and <osgi:reference> XML namespace elements. You can find more information on these in the Spring-DM reference manual.

    For further questions, I recommend you post to the official SpringSource dm Server forum. Doing so will allow more people to provide help, and in addition others will be able to profit from your questions.

    Regards,

    Sam


  21. Hello Sam,

    I just added the project reference and it worked fine :) . Thanks for your guidance.
    Next time onwords I will post my queries on forum.

    Thanks and Regards,
    Rahul


  22. Hi, I have a question regarding the migration of a war file to shared-lib war. I have a web application using axis2 framework. Where will I start? Do I have to delete all the jars files in webdemo/WEB-INF/lib then update my webdemo/META-INF/Manifest.mf and import the lib/bundle from my spring dm server's repository? Thanks.

4 trackbacks

Leave a Reply