- Monitoring (1)
- All articles (246)
- Installation (10)
- Getting started with Liberty (6)
- Migration (1)
- Coding (59)
- Java EE (57)
- OSGi (16)
- Setting up your Liberty workflow (10)
- Extending Liberty (7)
- Liberty with open source (17)
- DevOps (67)
- Security (9)
- Internet of Things (7)
- Real-time comms (1)
- Microservices (3)
- Cloud (29)
- Labs (3)
- Fun projects (9)
- Videos (34)
- Podcasts (5)
- Early Access (11)
We show how to deploy an OSGi application to Liberty in Cloud Foundry. We use an existing OSGi application tutorial to help you create the OSGi web application and then we describe how to deploy it.
Deploying to the cloud means you can share your application with the rest of the world without having to go through all the hassle of setting up all the infrastructure. You bring the application and the cloud does the hard work for you. So let’s get started!
Setting up the development environment
We are going to base these instructions on using the Eclipse IDE so install Liberty Profile and WebSphere Developer Tools:
- Download and install the WebSphere Application Server Liberty Profile
- Download and install the WebSphere Application Server Developer Tools for Eclipse
Getting started with Cloud Foundry
To use the Cloud Foundry cloud you will need an account and the command line tool:
Your environment is now ready for you to create your OSGi web application.
Creating an OSGi web application
To create your first OSGi web application, follow Lesson 1 to Lesson 5, which provides detailed instructions on how to create a simple counter application. The application will display a simple message of “counter=1” in the browser and every time the page is reloaded it will increment the counter. When the instructions ask you to to choose the “Target runtime” you’ll want to use the Liberty Profile server you’ve just installed.
Once you have finished Lessons 1 through 5, you will be ready to export an EBA (the archive format for OSGi applications used by Liberty Profile) file and deploy that EBA to Cloud Foundry.
Deploying the OSGi web application to Liberty in the cloud
Cloud Foundry has the concept of build packs that allow different runtimes to be enabled for the Cloud Foundry environment. Cloud Foundry has a Liberty Build Pack for running applications on Liberty in the Cloud. This includes support for the OSGi web application that you created in the earlier steps.
To deploy your application to the cloud:
- Export the CounterApp application you created above as an EBA:
- Right-click the CounterApp project; click Export > OSGi Application (EBA).
- In the dialog, clear the Replace qualifier with time stamp option.
- In the To EBA File: field type in
- Click Browse next to the To EBA File: field and create a
CounterApp/dropinsfolder on your desktop.
- Click Finish.
- The CounterApp.eba file should be created in the CounterApp/dropins folder
- Export the server.xml file into the CounterApp folder:
- In the Enterprise Explorer view, expand WebSphere Application Server V8.5 Liberty > servers > defaultServer.
- Right-click server.xml and click Export.
- In the dialog that opens, expand General and select File System then click Next.
- In the To directory: field, click Browse and select the CounterApp folder you created earlier, then click Finish.
- Edit the server.xml file:
- Using your favorite editor, open the server.xml file you just exported.
- Delete the following tags (these lines are specific to the eclipse environment that was created in the tutorial and they will not work properly in the cloud environment):
<applicationMonitor>(delete the entire tag line)
<osgiApplication>(delete the entire tag line)
- Save the file.
- In a terminal or command window, change directories to the CounterApp directory and issue the following command:
cf push --name counterapp --buildpack https://github.com/cloudfoundry/ibm-websphere-liberty-buildpack
- Accept the default values for all the questions that are asked during the push process.
Your OSGi web-based application is pushed to the cloud and, when it has completed, a URL to open your application will be displayed. For the CounterApp application, go to http://counterapp.cfapps.io/CounterWebBundle/CounterServlet.