Deploy Java Web project walkthrough based on IBM Bluemix

Source: Internet
Author: User
Tags throw exception

Lin Bingwen Evankaka Original works. Reprint please specify the source Http://blog.csdn.net/evankaka

Summary: This article focuses on IBM Bluemix and details how to deploy Java Web projects and how to add MySQL services. Finally, put forward some of their own views.

Article Directory
    • First, Bluemix Brief introduction
    • Second, Bluemix space application trial
    • Third, Bluemix create cloud Foundry App
    • Iv. Adding a new service
    • V. Summary

First, Bluemix Brief introduction

1. What does Bluemix bring?
Bluemix is committed to solving the problems described above in the software development process and is designed to help programmers develop, test, deploy, and ship dimension cloud Platform applications faster.
What is Bluemix?
Simply put, Bluemix is an open public cloud platform that allows programmers to run almost any type of application on top, without being distracted by hardware, software, networking and other factors. As mentioned above, Bluemix is in the middle tier of the cloud world, the PaaS layer. As shown in the following:

2. Reasons to choose Bluemix
first, to save time and effort, programmers can put all their mind on the application of writing and tuning, rather than worry about the complex platform infrastructure and facilities, more conducive to the development of programmer's creativity, to develop higher quality, high-performance applications;

Second, accelerate the application on-line, in the actual operation, only a few simple commands or a few clicks of the UI interface can easily complete the deployment of a variety of applications, without worrying about hardware procurement, software installation and so on these preparatory work;

Thirdly, it is easy to meet the needs of the application for a variety of new features and services, IBM and its partners to provide quality services, programmers only need to simple "bind" operation can be added to the application of services;

Finally, Bluemix's supported languages, runtimes, frameworks, and so on are all familiar to programmers, and the Bluemix platform requires virtually no new learning costs; The last point is that the Bluemix bottom-up IaaS is a Softlayer that can provide enterprise-class requirements, It can effectively guarantee the high performance and high security of the platform.

Second, Bluemix space application trial

1. Enter the official website

Official homepage: https://console.ng.bluemix.net/can be seen, mainly divided into three major categories, CF applications, containers and virtual machines.


2. Registration

Bluemix currently has no restrictions on user registration for free, and each registered user has 30 days of free use, and after a free trial, they don't know what will happen. The registration process is also simple, just a little bit better.


3. Activate login

This is the control Panel for Bluemix space and you can see that the operations are divided into 4 sections: Cloud Foundry, docker containers, virtual machines, services, and APIs. where the virtual machine is to pay money to be able to use. No free trial.


4. Create a space

By default you will automatically create a space called Dev, and of course you can recreate the new space yourself.


Note: When the initial application, cloud Foundry, containers are free trial 2GB, but one months after the need to bind a credit card, Cloud Foundry can always be free to use the quota is 256MB space.

Third, Bluemix create cloud Foundry app

Here's how to deploy the Javaweb project in Bluemix and package the local Javaweb project into Bluemix.
1. Create

Click the Create Cloud Foundry app in the Bluemix Control Panel


Choose a web App or a mobile app. Here I choose the Web application


2. Select the type of application

You can choose your app type to support liberty for Java, SDK for node. js, Go, PHP, Python, Ruby, ASP. NET 5, IBM XPages, community buildpack, and personal code. Here I choose liberty for Java


Then click Continue to proceed to the next step

3. Naming

After selecting the app, then fill in the app name and click Done.


5. Select the Code

Once the app is created, the next step is to start coding, which comes in three ways: Eclipse plug-ins, cf, and Git. The use of CF in this way is the simplest, this article is also used in this way, it is recommended that you use this way.


6. Install CF command line interface

CF mode is easy to encode, click the CF button, then you are prompted to install the CF command tool and download the starter code package.

Here are two main steps:



7. CF Command tool download

CF Command Tool official website: https://github.com/cloudfoundry/cli/releases, support for Debian with the-bit, Redhat-bit and-bit, Mac OS X bit, Window S-A-bit and a-bit, here is the CF command tool for Windows 32-bit and CF command tools Windows 64-bit.

8. Download the Application starter code package

Download your App starter Code package and you'll be able to see the file after extracting it, which is an example of the app code package that Bluemix provides to you. Only by downloading this starter code package can you connect to your personal Bluemix center, via your computer's console (Win +r, then enter cmd, OK) to operate your personal Bluemix Center

The path to the download is in the following: The blue button below, there is the path of the download!


If you can't find it, go to a personal-created project and click Start Editing


After the starter code decompression content, such as Javahelloworld.war is the default entry into this page access to the content http://javawebproject.eu-gb.mybluemix.net/. Our default personal Bluemix Center in the war package is the following, which is to replace the war package in the personal Bluemix Center.


9. Connect and log in to your personal Bluemix center

Open the Windows Command tool, and the CD enters into the folder where you store the starter code and connects to the BLUEMIX:CF API Https://api.ng.bluemix.net. , notice, here I put the extracted files directly under the C-drive.

(1) Enter the catalogue


(2) Connect to Bluemix

CF API Https://api.ng.bluemix.net


(3) Login to Bluemix

cf-u [email protected]-o [email protected]-s Dev
-U after the user,-s behind the creation of space, where I directly use the default, if you create a space to remember to change, and then enter the password can be


After doing this, this black box has been open, the operation of the background need to apply here!

10. Package The local war file

First, look at the local running effect, create a new Web project under MyEclipse (or Eclipse), and then write the content, here is not a small story, the local launch Tomcat after the effect of running up the following:


Then the entire project's war file is exported: In the workspace selection to the project, and then in the File->export, the following content pops up. Input the corresponding parameters can be



11. Upload the local war package to Bluemix

After the local Java Web project is packaged into a war package, use the command,

CF Push Javawebproject-  p D:\JavaWeb\JavaWebHello.war-m 512
Be sure to remember the path and name of the local war package followed by-p

Next it will be automatically uploaded. Encode, redeploy. The process is likely to wait a few minutes. Finally, if the following appears, the publication is successful.


12. Visit

Enter http://javawebproject.eu-gb.mybluemix.net/in your own browser (now you can access it, it will be up to 2015.11.30, and you may not be able to access it)

The animation is as follows: Here is a simple JSP-written page that counts the number of times a visit is made


Iv. Adding a new service

Here's a small page that mysql+servlet+jsp implement user login, and eventually deploy MySQL database and page to IBM Bluemix, with the final result:


1. Add MySQL Service

(1), open your own project. Add a service or API


(2), there are many services, you can choose


We can filter by search, enter MySQL


(3) Create a service


After it is created it will require you to recompile the package, OK is


(4) Binding service

How do you see that the database service has been bundled with our project? Very simple. You can see it after you enter the project!



2. Local access to the remote MySQL database

That is, then the database is created, then the next is to create a data table, while inserting some initial data to verify!

(1), view database source information

Or above, select Show credentials, here is the remote database name, access to the user name, password!

Here name is the database, hostname is the remote address of the database, username is the user name, password is the password, jdbcurl this is for JDBC, or spring in the configuration of the data source can be used


(2), local connection to personal Bluemix MySQL service

Open our MySQL Workbench (the local computer has a MySQL will have), select Database->connect to Database, in the pop-up box, enter the following content


(3) Create a table, insert data

Once the above is determined, we can connect to the remote database, and the next step is to build the table, insert a piece of data

The script is as follows:

Create database example;  use example;  CREATE TABLE User (  userid int primary key auto_increment,  name varchar () not NULL,  password varchar (in) not NULL  );  Insert into User (Userid,name,password) VALUES (null, ' Lin ', ' 1234 ');  


You can see that the database name AD_AB59B5772BF96A3 is the database in the corresponding materialized credential.

Next verify the data below to see if the insert was successful.


3. Build a Web Project

Database has, then the next is through the Web project to connect, the data query!

The creation of the entire Web project does not say, do not know to see here Servlet+jsp+mysql User login instance, project download path here http://download.csdn.net/detail/evankaka/8714563

Here's a look at the code that connects the database, change jdbcurl, username, password to the content of your own bluemix-created MySQL service, and then package it as a war package, or you can use it directly.

/** * Function Definition Database Operation class * author Lin Bingwen ([email protected] Blog: http://blog.csdn.net/evankaka) * Time 2015.4.22*/package COM.MUCFC.DBC Import Java.sql.connection;import Java.sql.drivermanager;public class DatabaseConnection {//define database driver private static Final string dbdriver= "Com.mysql.jdbc.Driver";//database connection address private static final string dburl= "jdbc:mysql:// US-CDBR-IRON-EAST-03.CLEARDB.NET/AD_AB59B5772BF96A3?USER=B1B48DEC447479&PASSWORD=1AA5DC06 ";//    Company represents the database private static final string dbuser= "b1b48dec447479";p rivate static final string dbpass= "1AA5DC06";    Private Connection Connection=null;    Public DatabaseConnection () throws exception{try{//Database operation may occur abnormally class.forname (dbdriver);        Connection=drivermanager.getconnection (Dburl,dbuser,dbpass);    }catch (Exception Exception) {throw Exception;    } finally {}} public Connection getconnection () {return Connection; public void Close () throws exception{if (connection!=null) {try {connection.close ();} catch (EXception e) {throw e;} }        }}
This is it, local to run down the Web Project!!! The effect is as follows


4. Fight the war package and upload the war package

The final key step is of course uploaded!

The packing process has been mentioned above and is no longer detailed here. Name the entire packaged war package Javaweblogin.war

Upload command: Be sure to select through the CF API and then CF login to log in to your space before using the CF PUSH command!!! , and also note the path and name of the Upload War package!!


The final output is as follows, indicating success:


5. VisitOpen the browser and enter http://javawebproject.eu-gb.mybluemix.net/(which is still accessible until 2015.11.30) correct username/password: lin/1234The effect is as follows:

v. Summary
Advantages: 1, free to use 30 days, 2G applications, 2G containers, 10 services 2, the overall operation is relatively simple, for the operation and maintenance of personnel can also learn 3, the function is complete, light application support a lot of kinds, there are virtual machines, containers, services shortcomings: 1, response too slow, behind the deployment of the login Web project, Because of the connection of the database, verify that the return of nearly 2 seconds, if the table is more, more data, do not know the reliability can guarantee 2, online tutorials Less, especially about the container this piece, the entire Bluemix website response is very slow!

Reference article:IBM PAAs platform Bluemix Free application to use cloud Foundry,docker containers and virtual machines to explore IBM Bluemix


Copyright NOTICE: This article for Bo Master Lin Bingwen Evankaka original article, reproduced please indicate the source Http://blog.csdn.net/evankaka

Deploy Java Web project walkthrough based on IBM Bluemix

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.