Sunday, May 11, 2014

How to use eclipse to develop liberty java application to BlueMix Part Two

Before you begin, make sure you have installed the Liberty and BlueMix plug-in in the  previous blog.

1.Create a HelloWorld Web project from Eclipse and make sure you have choose the traget runtime with was liberty profile.

2.Create a servlet named  HelloWolrd ,and generate get and set method.Write the below code to the doGet method.

/**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        PrintWriter p = response.getWriter();
        p.println("<BODY>");
        p.println("<H2>This a blueMix demo");
        p.println("</BODY>");
    }

3.Start the WebSphere Application Server Liberty Profile at localhost ,choose the server and add your hellow world project to the runtime server,so you can do the local testing for that.

Notes:Sometimes your liberty default 9080 might be occupied,so you might need to change httpPort in the server.xml

<server description="new server">

    <!-- Enable features -->
    <featureManager>
        <feature>jsp-2.2</feature>
        <feature>localConnector-1.0</feature>
    </featureManager>

    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
    <httpEndpoint httpPort="9085" httpsPort="9443" id="defaultHttpEndpoint"/>


    <applicationMonitor updateTrigger="mbean"/>

    <webApplication id="HelloWorld" location="HelloWorld.war" name="HelloWorld"/>
</server>

 4. Launch the url in the web console ,open the browser to do the testing

5.Once you liberty application is ready on local side, you can deploy it to the BlueMix,The step is very simple.Choose the IBM  BlueMix server and add your project into it.
6.During the deployment,it will let you change the application detail info,deployment detail,service selection info.

Pls make sure the deploy url is not used by others,otherwise the deployment will be failed

If you don;t use other service,just click  to next.
If the deployment is sucessful,you can see your liberty application is already deployed in the BlueMix.

7.Visit the BlueMix url http://helloworld001.ng.bluemix.net/HelloWorld

Now our first HelloWorld Liberty demo is completed,enjoy it.



2 comments: