IBM Bluemix http://ibm.biz/bluemixph A platform where developers can act like kids in a sandbox except this box is enterprise-grade. This laboratory exercise demonstrates how to connect Eclipse to Bluemix and upload an application to Bluemix using Eclipse. Prerequisite Item Eclipse Bluemix Account Comment do the Setting-up Laboratory Environment (section: Installing Eclipse) laboratory exercise to install Eclipse do the Creating a Bluemix Account laboratory exercise if you do not have a Bluemix account Downloading Sample WAR File 1. Go to a GitHub repository (https://github.com/ibmjstart/bluemix-java-postgresql-upload/releases)/ 2. Click the PostgreSQLUpload.war button to download the WAR file. Save the WAR file under c:\bluemixtemp. Note: There might be several versions of the WAR file. Download v1.1. 3. The PostgreSQLUpload WAR file is a sample Java web application that uses a PostgreSQL database. It asks for a text file from user and saves each line in the text file as a row in a table in the database. Note: Once you have completed this laboratory exercise, you may use the procedure as a basis to upload and your own WAR file to Bluemix using Eclipse. 1
Download Sample WAR File 1. Launch Eclipse. Close the Welcome tab. 2. In the menu, click Help->Eclipse Marketplace. 3. In the Eclipse Marketplace search for cloud foundry. Look for the item titled: "Cloud Foundry Integration for Eclipse x.x.x". Click Update (or Install ) to update (or install) Cloud Foundry Integration for Eclipse. 2
Setting-up Bluemix Server 1. In the bottom window section of Eclipse, select the Servers tab. 2. Right-click inside the Servers panel and select New > Server. 3
3. In New Server: Define a New Server window, select Pivotal->Cloud Foundry. Click Next. 4
4. In New Server: Cloud Foundry Account window, click Manage Cloud. 5. In Manage Cloud URLs window, click Add. 5
6. In Add and validate a Cloud URL window, enter Bluemix in the name field and https://api.ng.bluemix.net in the URL field. Click Finish. 7. In the Manage Cloud URLs window, click Ok. 6
8. In New Server: Cloud Foundry Account window, make sure that the URL is Bluemix https://api.ng.bluemix.net. Enter your Bluemix username and password in the Email and Password fields, respectively. Click Validate Account. Once the account is validated, click Finish. 7
Import the WAR file to Eclipse 1. In the menu, click File->Import. 8
2. In the Import: Select window, select Web->WAR File. Click Next. 9
3. In the Import: WAR Import window, click Browse. 10
4. In the Open window, select the PostgreSQLUpload.war file under the folder c:\bluemixtemp. Click Open. 11
5. In the Import: WAR Import window, click Finish. 12
Uploading the Application in Bluemix 1. In the bottom window section of Eclipse, select the Servers tab. 2. Right-click on the Bluemix server (Pivotal Cloud Foundry) and click Connect. Note: If the Connect entry is disabled and the Disconnect entry is enabled, it means that Eclipse is already connected to the Bluemix server. 13
3. Right-click on the Bluemix server (Pivotal Cloud Foundry) and click Add and Remove. 4. In the Add and Remove window, select PostgreSQLUpload in the left pane and click Add. 14
5. In the Add and Remove window, click Finish. Note: Aside from PostgreSQLUpload, it is possible that there are other applications listed in the right pane. These are the applications that are currently available in your Bluemix account. In the screenshot below, the application jpu-john is available in the demo account. 15
6. In the Application: Application details window, enter textfileuploader-<your name> in the Name filed. Click Next. 7. In the Application: Launch deployment window, take note of the Deployed URL field. Click Finish. 16
8. In the bottom window section of Eclipse, select the Console tab (if necessary). Wait for the The server defaultserver is ready to run a smarter planet message to appear. 9. Open a browser. Access your uploaded application (http://textfileuploader-<you name>.mybluemix.net/) 10. You may test your application by uploading a text file. 17
Edit Application and Redeploy in Bluemix 1. In the Project Explorer expand PostgreSQLUpload->Java Resources->com.ibm.bluemix.samples. Double-click PostgreSQLClient.java to open it. Scroll-down until you see the createtable() method. 2. You can modify this method to create the tables you need for your application. You can modify also other files as needed. 3. Assuming that you have done the necessary modifications, you can redeploy your application. 4. In the bottom window section of Eclipse, select the Servers tab. Expand the Bluemix server (Pivotal Cloud Foundry). 5. Right-click on the PostgreSQLUpload application, and click Update and Restart. 18
6. In the bottom window section of Eclipse, select the Console tab (if necessary). Wait for the The server defaultserver is ready to run a smarter planet message to appear. 7. Refresh the browser to see the changes in your application. 19