Date Created: Fri 21-Jan-2011

Related Document Categories:


    Creating WAR application using the Todo source from ZKForge and deploy to WebSphere 8 & MySQL Server.

    Here is the code:

    todo_mysql.ear<< contains Java Source Code of what you see below.

    This is what I did to get the ToDo sample application from ZKforge working on Websphere 8 using the MySQL Driver. It is not an enterprise solution. It is designed to help anyone wanting to do a quick review of ZK i.e. changing to use WAS 8 and MySQL as opposed to Tomcat and HSQLDB.

    I downloaded the Download GNU tarball


    http://zkforge.svn.sourceforge.net/viewvc/zkforge/trunk/todo/


    Using Eclipse ,so we can import the downloaded source code.



    Selected the todo source tree on the file system





    I had to remove the older version of the JRE as I am now using JDK 6, and I am not using Tomcat 5.5, so I am removing both libs.




    I added JavaSE 1.6 (Java 6)



    I then got this error

    "This project needs to migrate WTP metadata"



    Right-Mouse Click and select validate



    I have been lazy and not opted to update the Java generics, will do later. Lets see if it works.

    What I did was export the project to the automatic deploy directory of WebSphere 8

    Note: A better way to create a project with less errors is to create the dynamic web project in Eclipse first,then just paste the source code into the src folder as created by the new project wizard, then right-mouse click on the project and refresh it.

    I go this error

    Caused by: com.ibm.ws.webcontainer.exception.WebAppNotLoadedException: Failed to load webapp: Context root /* is already bound. Cannot start application zk Tutorial Example
    at com.ibm.ws.webcontainer.VirtualHostImpl.addWebApplication(VirtualHostImpl.java:133)
    at com.ibm.ws.webcontainer.WSWebContainer.addWebApp(WSWebContainer.java:743)

    This was because I tried to deploy a WAR file to the default context root. the way to solve tis is top create an EAR project and Assign the WAR.

    I factored and renamed the ToDo project to "ToDoWAR"




    I then created a new EAR project






    On the next step I added the ToDoWAR project to the new ToDoEar project.




    I then edited application.xml to

    <?xml version="1.0" encoding="UTF-8"?>
    <application id="Application_ID" version="1.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
    <display-name>ToDoEAR</display-name>
    <module id="WebModule_1293132369890">
    <web>
    <web-uri>ToDoWAR.war</web-uri>
    <context-root>todo</context-root>
    </web>
    </module>
    </application>

    So I now have todo as the context root.

    Lets try an auto deployment again.

    C:\IBM\WebSphere\AppServer\profiles\AppSrv01\monitoredDeployableApps\servers\server1\todo.ear




    I got the following error

    Caused by: com.ibm.wsspi.injectionengine.InjectionException: CWNEN0044E: A resource reference binding could not be found for the following resource references [jdbc/potix], defined for the zk Tutorial Example component.
    at com.ibm.wsspi.injectionengine.InjectionProcessor.collectInjectionNBindingData(InjectionProcessor.java:1342)
    at com.ibm.ws.injectionengine.InjectionEngineImpl.processBindings(InjectionEngineImpl.java:714)

    I now need to add a JDBC connection to a database,

    Well this application uses hsqldb a Java Database, I am going to re-factorand connect to a MySQL Database.

    ================================


    Looking at web.xml I found and removed due to my statement below.


    <resource-ref>
    <res-ref-name>jdbc/potix</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>

    However there is not code that uses this resource reference. the code I did find was:

    private String url = "jdbc:hsqldb:file:/hsqldb/event";

    private String user = "sa";

    private String pwd = "";

    public EventDAO() {
    try {
    Class.forName("org.hsqldb.jdbcDriver");
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    }
    }

    So I need to decide to either use JDBC with resource bindings or just go direct. I am being lazy tonight, so I am going to use MySQL and code directly using a JDBC driver connection. This approach is not recommended for enterprise development, only good for concepts.

    I modified the code as EeventDAO.java as follows

    private String url = "jdbc:mysql://www.mydomain.com:3306/todo";

    private String user = "todo";

    private String pwd = "todo";

    public EventDAO() {
    try {
    Class.forName("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    }
    }

    and added mysql-connector-java-5.1.13-bin.jar to the project.

    I also had to create a DB on MySQL, reading through the code I created a DB caled Todo and A table called EVent with these fields:

    id (String)
    name (String)
    priority (int)
    date (DateTime)


    SQL used in MYSQL


    CREATE TABLE `zktodo`.`event` (
    `id` VARCHAR( 255 ) NOT NULL ,
    `name` VARCHAR( 255 ) NOT NULL ,
    `priority` INT NOT NULL ,
    `date` DATE NOT NULL

    ) ENGINE = MYISAM ;


    Result is a successful wokring application using MYSQL






    ====== WebSphere Deployment Log ==================

    Note: Automatic drag/drop deployment is not good for production where you may have to change class loaders and/or other JVM or config settings relating to a deployment.


    [23/12/10 19:55:17:068 GMT] 00000025 AppManagement I CWLDD0014I: Event id 2027903608-4. Installing application todo...
    [23/12/10 19:55:18:870 GMT] 00000067 InstallSchedu I ADMA5013I: Application todo installed successfully.
    [23/12/10 19:55:21:063 GMT] 00000025 AppBinaryProc I ADMA7021I: Distribution of application todo completed successfully.
    [23/12/10 19:55:21:116 GMT] 00000025 FileRepositor A ADMR0015I: User defaultWIMFileBasedRealm/server:T60Windows7PNode01Cell_T60Windows7PNode01_server1 created document cells/T60Windows7PNode01Cell/applications/todo.ear/todo.ear.
    [23/12/10 19:55:21:119 GMT] 00000025 FileRepositor A ADMR0015I: User defaultWIMFileBasedRealm/server:T60Windows7PNode01Cell_T60Windows7PNode01_server1 created document cells/T60Windows7PNode01Cell/cus/todo/cver/BASE/cu.xml.
    [23/12/10 19:55:21:122 GMT] 00000025 FileRepositor A ADMR0015I: User defaultWIMFileBasedRealm/server:T60Windows7PNode01Cell_T60Windows7PNode01_server1 created document cells/T60Windows7PNode01Cell/blas/todo/bver/BASE/bla.xml.
    [23/12/10 19:55:21:128 GMT] 00000025 FileRepositor A ADMR0015I: User defaultWIMFileBasedRealm/server:T60Windows7PNode01Cell_T60Windows7PNode01_server1 created document cells/T60Windows7PNode01Cell/applications/todo.ear/deployments/todo/ToDoWAR.war/META-INF/MANIFEST.MF.
    [23/12/10 19:55:21:131 GMT] 00000025 FileRepositor A ADMR0015I: User defaultWIMFileBasedRealm/server:T60Windows7PNode01Cell_T60Windows7PNode01_server1 created document cells/T60Windows7PNode01Cell/applications/todo.ear/deployments/todo/META-INF/ibm-application-runtime.props.
    [23/12/10 19:55:21:134 GMT] 00000025 FileRepositor A ADMR0015I: User defaultWIMFileBasedRealm/server:T60Windows7PNode01Cell_T60Windows7PNode01_server1 created document cells/T60Windows7PNode01Cell/cus/todo/cver/BASE/cu-ref.xml.
    [23/12/10 19:55:21:179 GMT] 00000025 FileRepositor A ADMR0015I: User defaultWIMFileBasedRealm/server:T60Windows7PNode01Cell_T60Windows7PNode01_server1 created document cells/T60Windows7PNode01Cell/applications/todo.ear/deployments/todo/META-INF/application.xml.
    [23/12/10 19:55:21:202 GMT] 00000025 FileRepositor A ADMR0015I: User defaultWIMFileBasedRealm/server:T60Windows7PNode01Cell_T60Windows7PNode01_server1 created document cells/T60Windows7PNode01Cell/applications/todo.ear/deployments/todo/META-INF/MANIFEST.MF.
    [23/12/10 19:55:21:239 GMT] 00000025 FileRepositor A ADMR0015I: User defaultWIMFileBasedRealm/server:T60Windows7PNode01Cell_T60Windows7PNode01_server1 created document cells/T60Windows7PNode01Cell/applications/todo.ear/deployments/todo/ToDoWAR.war/WEB-INF/web.xml.
    [23/12/10 19:55:21:244 GMT] 00000025 FileRepositor A ADMR0015I: User defaultWIMFileBasedRealm/server:T60Windows7PNode01Cell_T60Windows7PNode01_server1 created document cells/T60Windows7PNode01Cell/cus/todo/cver/BASE/controlOpDefs.xml.
    [23/12/10 19:55:21:248 GMT] 00000025 FileRepositor A ADMR0015I: User defaultWIMFileBasedRealm/server:T60Windows7PNode01Cell_T60Windows7PNode01_server1 created document cells/T60Windows7PNode01Cell/applications/todo.ear/deployments/todo/deployment.xml.
    [23/12/10 19:55:21:250 GMT] 00000025 FileRepositor A ADMR0015I: User defaultWIMFileBasedRealm/server:T60Windows7PNode01Cell_T60Windows7PNode01_server1 created document cells/T60Windows7PNode01Cell/applications/todo.ear/deltas/todo/delta-1293134118744.
    [23/12/10 19:55:21:253 GMT] 00000025 FileRepositor A ADMR0016I: User defaultWIMFileBasedRealm/server:T60Windows7PNode01Cell_T60Windows7PNode01_server1 modified document cells/T60Windows7PNode01Cell/nodes/T60Windows7PNode01/serverindex.xml.
    [23/12/10 19:55:21:490 GMT] 00000025 AppManagement I CWLDD0015I: Event id 2027903608-4. Application todo is installed successfully.
    [23/12/10 19:55:21:493 GMT] 00000025 AppManagement I CWLDD0020I: Event id 2027903608-4. Starting application todo...
    [23/12/10 19:55:21:510 GMT] 00000025 AdminHelper A ADMN1008I: An attempt is made to start the todo application. (User ID = defaultWIMFileBasedRealm/server:T60Windows7PNode01Cell_T60Windows7PNode01_server1)
    [23/12/10 19:55:21:579 GMT] 00000025 CompositionUn A WSVR0190I: Starting composition unit WebSphere:cuname=todo in BLA WebSphere:blaname=todo.
    [23/12/10 19:55:21:656 GMT] 00000025 ApplicationMg A WSVR0200I: Starting application: todo
    [23/12/10 19:55:21:659 GMT] 00000025 ApplicationMg A WSVR0204I: Application: todo Application build level: Unknown
    [23/12/10 19:55:21:920 GMT] 00000025 webapp I com.ibm.ws.webcontainer.webapp.WebGroupImpl WebGroup SRVE0169I: Loading Web Module: zk Tutorial Example.
    [23/12/10 19:55:22:168 GMT] 00000025 WASSessionCor I SessionContextRegistry getSessionContext SESN0176I: Will create a new session context for application key default_hosttodo
    [23/12/10 19:55:23:475 GMT] 00000025 servlet I com.ibm.ws.webcontainer.servlet.ServletWrapper init SRVE0242I: [todo] [/todo] [zkLoader]: Initialization successful.
    [23/12/10 19:55:23:478 GMT] 00000025 webcontainer I com.ibm.ws.webcontainer.VirtualHostImpl addWebApplication SRVE0250I: Web Module zk Tutorial Example has been bound to default_host[*:9080,*:80,*:9443,*:5060,*:5061,*:443].
    [23/12/10 19:55:23:508 GMT] 00000025 ApplicationMg A WSVR0221I: Application started: todo
    [23/12/10 19:55:23:512 GMT] 00000025 CompositionUn A WSVR0191I: Composition unit WebSphere:cuname=todo in BLA WebSphere:blaname=todo started.
    [23/12/10 19:55:23:529 GMT] 00000025 AppManagement I CWLDD0021I: Event id 2027903608-4. Application todo is started on: WebSphere:cell=T60Windows7PNode01Cell,node=T60Windows7PNode01,server=server1,status=success.
    [23/12/10 19:55:23:532 GMT] 00000025 WatchService I CWLDD0008I: Event id 2027903608-4. End of processing.






Middleware Mentor - Steven Charles Robinson

About Me

Steve Robinson has been working in IT for over 15 years and has provided solutions for many large-enterprise corporate companies across the world. Steve specialises in Java and Middleware consulting. Steve comes from both an administration and development background.

Before moving to JEE, Steve was an accomplished developer and consultant for both IBM Lotus Notes and Microsoft .NET Technologies.

Follow Steve as @stevencrobinson on twitter.

Read my books?

IBM WebSphere Application Server 8.0 Administration Guide

IBM WebSphere Application Server 8.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Categories

Oracle WebLogic Categories

JBoss Categories

Other Categories