Date Created: Thu 02-Dec-2010

Related Document Categories:

Get my WebSphere Application Server course here >> http://www.themiddlewareshop.com/products/


    Creating a WebService using Eclipse - Part 1

    We can essentially build a WebService in two ways. Bottom up which takes an existing Java Bean and presents as a web service or we can use top-down to take an existing WSDL and generate the web service.

    What we will do is build a Server side webservice for example an endpoint and consume SOAP requests. We will then build a client using the Server side WebService's WSDL.

    What We will do is import an existing EAR file and create a WebServices wrapper.

    The EAR file essentially is an environment variable query tool servlet and it takes a QS parameter i.e. the name of a Linux environment and shoes whether the application container can actually see that Linux variable. If it doesn't see the variable then we know that the user (shell) that the container run under does not have the environment variable set. Note: It is not good practice to use environment variables, we really should use JVM arguments. We will deal with this as we go through the example.

    The EAR needs fixing as well as it is not in working 100% we will fix the ear and allow it work better as a servlet then make it automatically deployable then wrap it has a service.


    Note: Was developed originally for WebSphere.

    Import an existing EAR









    Because I selected Oracle WebLogic as the target runtime, Eclipse parses the project and makes it WL ready i.e. adds weblogic.xml etc.

    Next







    Eclipse sees the WAR as two seperate project files, ie a WAR within a EAR. We need to add to SVN
















    Finish


    Do the same for the WAR project



    FYI if you open the SVN Synchronisation perspective and views you can get a view of the repository state for a given project. A perspective changes the IDE perspective and view are added to the current perspective (layout)



    Lets look at the application src code. If we exa=pand we see two classes.



    To see how these might be used we can look at the existing web.xml (Web Application Deployment Descriptor)



    We can see that there is a servlet called "GetEnvVars" and the mapping is /GetEnvVar which means the user has to type <context_root>/GetEnvVar to envoke the servlet.

    it is case sensitive so I cam going to change it to lower-case

    <servlet-mapping>
    <servlet-name>GetEnvVar</servlet-name>
    <url-pattern>/getenvvar</url-pattern>
    </servlet-mapping>

    Check the code in

    Look for web.xml



    right-mouse-click and commit to SVN.


    Log can be fond in the console view




    At this time the rest of project is marked for Source control, however it still local.

    If we want to send the entire application to the repository we sleect the project and click commit.


    To protect you application we commit the EAR as well for safe keeping



    At this time we still have some IBM artifacts to remove form this project to keep it pure WL. We can do this later. We can address this when we want to use ANT to build as WebSphere ready application.


    GetEnvVars

    The GetEnvVars class implements the Servlet interface and thus makes it a servlet. It is also using a class called OSEnvironment which contaisn static methods, which means the class does not have to instantiated as an object to call the methods. This is a great feature and has it uses. If we wished to have objects that represent many instances of a class then the methods i.e member functions (c++) would act on the data (object) itself as an entity. We are essentially just using the class to act as a container (organisational container) for methods and we do not need to store state in the object and so in reality we have a single object of which we are going to call member functions to carry out work.

    package com.webspheretools;

    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.PrintWriter;

    /**
    * Servlet implementation class for Servlet: GetEnvVars
    *
    */
    public class GetEnvVars extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
    static final long serialVersionUID=0;
    /* (non-Java-doc)
    * @see javax.servlet.http.HttpServlet#HttpServlet()
    */
    public GetEnvVars() {
    super();
    }

    /* (non-Java-doc)
    * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
    getEnvVar(request, response);
    }
    catch(Exception e){
    System.out.println(e.getMessage());
    }

    }

    /* (non-Java-doc)
    * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    }

    private void getEnvVar(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String strEnvVarName = (String)request.getParameter("env");
    String strEnvValue = "";

    strEnvValue = OSEnvironment.getProperty(strEnvVarName);


    response.setContentType("text/plain");
    // Always set the Content Type before data is printed
    PrintWriter out = response.getWriter();
    out.println( "<html>" );
    out.println( "<head>" );
    out.println( "<title>A Sample Servlet</title>" );
    out.println( "</head>" );
    out.println( "<body>" );
    out.println( "<h1>"+strEnvVarName+"="+strEnvValue+"</h1>" );
    out.println( "</body>" );
    out.println( "</html>" );
    out.close();


    }
    }


    Essnetially when the sevlet is called via GET is page is loaded or refreshed it will call the getEnvVar function.


    private void getEnvVar(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String strEnvVarName = (String)request.getParameter("env");
    String strEnvValue = "";

    strEnvValue = OSEnvironment.getProperty(strEnvVarName);


    response.setContentType("text/plain");
    // Always set the Content Type before data is printed
    PrintWriter out = response.getWriter();
    out.println( "<html>" );
    out.println( "<head>" );
    out.println( "<title>A Sample Servlet</title>" );
    out.println( "</head>" );
    out.println( "<body>" );
    out.println( "<h1>"+strEnvVarName+"="+strEnvValue+"</h1>" );
    out.println( "</body>" );
    out.println( "</html>" );
    out.close();


    }

    We need to comment out the line


    //response.setContentType("text/plain");

    because it is stopping the application from writing HTML

    Lets deploy it an see what happens before after the commented out code.




    After


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

    Quick Deploy to local WL for a test is easy, but if we want to deploy to server quickly then we need to create a an ANT script and use Hudson to deploy it.

    Lets do that quickly now, by using the HRApplication example ANT scripts as a base.

    We are building a Linux server side ant build file, not a local windows one. We can have both but I am sticking to server side as this is a more fundamental test going forward. It is not recommended to keep project local for too long before testing an actual server deployment.


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

    What I like to so is create a project to contain my server build scripts this way they are located in one place.

    Create generic project, which is to hold my build script to edited locally in the Eclipse editor but used only on the server with Hudson. A sort os disconnected simple way separating automated build away from the actual project files. You see the EAR and WAR are checked into SVN and so is the build project, the build project is to only get the build files server side it serves no other purpose. In this case the build are all run server side. there are may ways to do this this is just one logical way of separation (loose coupled build)






    Add a new xml file called ubuild.xml (u means unix side) my own way of telling the difference between local and server side.


    <?xml version="1.0"?>
    <project name="herear" default="makeear" basedir=".">
    <tstamp>
    <format property="buildtimestamp" pattern="yyyy-MM-dd'T'HH:mm:ss" />
    </tstamp>

    <echo message="------------------ Properties ------------------------------"/>
    <property name="root" value="${basedir}" />
    <echo message="root=${root}"/>

    <property name="EARBasePath" value="${root}/../EnvironmentWebEAR" />
    <echo message="EARBasePath=${EARBasePath}"/>

    <property name="WARBasePath" value="${root}/../EnvironmentWeb" />
    <echo message="WARBasePath=${WARBasePath}"/>

    <property name="lib.dir" value="${WARBasePath}/lib" />
    <echo message="lib.dir=${lib.dir}"/>

    <property name="src.dir" value="${WARBasePath}/src" />
    <echo message="src.dir=${src.dir}"/>

    <property name="pages.dir" value="${WARBasePath}/WebContent" />
    <echo message="pages.dir=${pages.dir}"/>

    <!-- put everything in a temp folder with the right structure during the build -->
    <property name="package.file" value="EnvironmentWeb.war" />
    <property name="temp.dir" value="temp" />
    <property name="dest.dir" value="dist" />
    <property name="temp.dir.web-inf" value="${temp.dir}/WEB-INF" />
    <property name="temp.dir.lib" value="${temp.dir.web-inf}/lib" />
    <property name="temp.dir.classes" value="${temp.dir.web-inf}/classes" />
    <property name="temp.dir.meta-inf" value="${temp.dir}/META-INF" />
    <property name="pages.dir" value="WebContent" />

    <!-- Set up a path id for external JARS reference during compilation of WAR Java files-->
    <path id="build.classpath">
    <fileset dir="/var/apps/weblogic10/wlserver_10.3/server/lib/">
    <include name="api.jar" />
    </fileset>

    </path>
    <echo message="----------------------------------------------------------"/>

    <!-- CLEAN LAST BUILD ATTEMP -->
    <target name="clean" depends="">
    <echo>=== CLEAN ===</echo>
    <delete dir="${temp.dir}" />
    <delete dir="${dest}" />
    </target>

    <!-- PREPARE FOLDERS FOR DISTRIBUTION -->
    <target name="prepare" depends="clean">
    <echo>=== PREPARE ===</echo>
    <mkdir dir="${dest.dir}" />
    <mkdir dir="${temp.dir}" />
    <mkdir dir="${temp.dir.lib}" />
    <mkdir dir="${temp.dir.meta-inf}" />
    <mkdir dir="${temp.dir.web-inf}" />
    <mkdir dir="${temp.dir.classes}" />
    </target>


    <!-- BUILD ALL -->
    <target name="all" depends="makeear">
    <echo>=== BUILD ALL ===</echo>
    <delete dir="${build}" />
    </target>



    <!-- COMPILE -->
    <target name="compile" depends="prepare">
    <echo>=== COMPILE ===</echo>
    <javac debug="on" srcdir="${src.dir}" destdir="${temp.dir.classes}">
    <classpath refid="build.classpath" />
    <compilerarg value="-Xlint:unchecked" />

    </javac>
    </target>


    <!-- PACKAGE WAR File -->
    <target name="makewar" depends="compile">
    <echo>=== PACKAGE WAR ===</echo>

    <!-- copy the config files -->
    <copy file="${WARBasePath}/WebContent/META-INF/MANIFEST.MF" tofile="${temp.dir.meta-inf}/MANIFEST.MF" overwrite="true" />
    <copy file="${WARBasePath}/WebContent/WEB-INF/web.xml" tofile="${temp.dir.web-inf}/web.xml" overwrite="true" />

    <!-- the ant war task. with all resources in place, create the war file -->
    <war destfile="${dest.dir}/${package.file}" webxml="${temp.dir.web-inf}/web.xml" basedir="${temp.dir}">

    <fileset dir="${pages.dir}">
    <include name="**/*.html"/>
    </fileset>
    <!--<lib dir="${lib.dir}" />-->
    <classes dir="${temp.dir.classes}" />
    </war>
    </target>

    <!-- PACKAGE EAR FILE -->
    <target name="makeear" depends="makewar">
    <echo>=== MAKE EAR ===</echo>
    <ear earfile="${dest.dir}/EnvironmentWebEAR.ear" appxml="${EARBasePath}/EarContent/META-INF/application.xml">
    <fileset dir="${dest.dir}">
    <include name="*.war"/>
    </fileset>
    </ear>

    </target>

    </project>

    Share and commit the new build project to SVN



    Lets look at the server now.



    svn/v3interact1ve

    mkdir /home/svn/working/project2

    This will be our working directory

    lets get SVN to create local copies in our working directory




    svn checkout http://linux.veinteractive.net/svn/ve_java_repo/trunk/JavaTraining/BuildEnvironmentEAR/
    svn checkout http://linux.veinteractive.net/svn/ve_java_repo/trunk/JavaTraining/EnvironmentWeb/
    svn checkout http://linux.veinteractive.net/svn/ve_java_repo/trunk/JavaTraining/EnvironmentWebEAR/

    Results etc

    [svn@s15382406 project2]$ svn checkout http://linux.veinteractive.net/svn/ve_java_repo/trunk/JavaTraining/BuildEnvironmentEAR/
    A BuildEnvironmentEAR/ubuild.xml
    A BuildEnvironmentEAR/.project
    Checked out revision 62.


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




    we can now see we have local copies of the three projects in the working folder on Linux

    cd /home/svn/working/project2/BuildEnvironmentEAR

    action a build with ant

    ant -f ./ubuild.xml

    [svn@s15382406 BuildEnvironmentEAR]$ ant -f ./ubuild.xml
    Buildfile: ./ubuild.xml
    [echo] ------------------ Properties ------------------------------
    [echo] root=/home/svn/working/project2/BuildEnvironmentEAR
    [echo] EARBasePath=/home/svn/working/project2/BuildEnvironmentEAR/../Enviro nmentWebEAR
    [echo] WARBasePath=/home/svn/working/project2/BuildEnvironmentEAR/../Enviro nmentWeb
    [echo] lib.dir=/home/svn/working/project2/BuildEnvironmentEAR/../Environmen tWeb/lib
    [echo] src.dir=/home/svn/working/project2/BuildEnvironmentEAR/../Environmen tWeb/src
    [echo] pages.dir=/home/svn/working/project2/BuildEnvironmentEAR/../Environm entWeb/WebContent
    [echo] ----------------------------------------------------------

    clean:
    [echo] === CLEAN ===

    prepare:
    [echo] === PREPARE ===
    [mkdir] Created dir: /home/svn/working/project2/BuildEnvironmentEAR/dist
    [mkdir] Created dir: /home/svn/working/project2/BuildEnvironmentEAR/temp
    [mkdir] Created dir: /home/svn/working/project2/BuildEnvironmentEAR/temp/WEB -INF/lib
    [mkdir] Created dir: /home/svn/working/project2/BuildEnvironmentEAR/temp/MET A-INF
    [mkdir] Created dir: /home/svn/working/project2/BuildEnvironmentEAR/temp/WEB -INF/classes

    compile:
    [echo] === COMPILE ===
    [javac] Compiling 2 source files to /home/svn/working/project2/BuildEnvironm entEAR/temp/WEB-INF/classes

    makewar:
    [echo] === PACKAGE WAR ===
    [copy] Copying 1 file to /home/svn/working/project2/BuildEnvironmentEAR/tem p/META-INF
    [copy] Copying 1 file to /home/svn/working/project2/BuildEnvironmentEAR/tem p/WEB-INF
    [war] Building war: /home/svn/working/project2/BuildEnvironmentEAR/dist/En vironmentWeb.war
    [war] Warning: selected war files include a WEB-INF/web.xml which will be ignored (please use webxml attribute to war task)

    makeear:
    [echo] === MAKE EAR ===
    [ear] Building ear: /home/svn/working/project2/BuildEnvironmentEAR/dist/En vironmentWebEAR.ear

    BUILD SUCCESSFUL
    Total time: 1 second


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

    Result




    If we cd dist we see....two files one WAR and one EAR



    We now need to create a depoyment build script called dbuild.xml



    <project basedir="." name="WebLogic Deploy" default="all">

    <!-- External dependencies. -->
    <property file="local.properties"/>
    <property environment="env"/>

    <echo message="weblogic.user=${weblogic.user}"/>
    <echo message="weblogic.password=${weblogic.password}"/>
    <echo message="weblogic.adminhost=${weblogic.adminhost}"/>


    <property name="ear.name" value="EnvironmentWebEAR" />
    <echo message="ear.name=${ear.name}"/>

    <property name="ear.src.name" value="dist/${ear.name}" />
    <echo message="ear.src.name=${ear.src.name}"/>

    <property name="ear.logic.name" value="EnvironmentWebEAR" />
    <echo message="ear.name=${ear.logic.name}"/>

    <path id="wls.classpath">
    <pathelement location="${env.WL_HOME}/server/lib/weblogic.jar" />
    <pathelement location="${env.WL_HOME}/server/lib/api.jar" />
    </path>

    <!-- Command Line Definitions -->
    <taskdef name="wldeploy"
    classname="weblogic.ant.taskdefs.management.WLDeploy"
    classpathref="wls.classpath"/>

    <!-- Targets -->
    <target name="deploy">
    <wldeploy verbose="true"
    upload="true"
    debug="true"
    user="${weblogic.user}" password="${weblogic.password}"
    adminurl="t3://${weblogic.adminhost}:7001" source="${ear.src.name}"
    action="deploy"/>
    </target>

    <target name="undeploy">
    <wldeploy verbose="true"
    user="${weblogic.user}" password="${weblogic.password}"
    adminurl="t3://${weblogic.adminhost}:7001" name="${ear.name}"
    action="undeploy"/>
    </target>

    <target name="redeploy">
    <wldeploy verbose="true"
    user="${weblogic.user}" password="${weblogic.password}"
    adminurl="t3://${weblogic.adminhost}:7001" name="${ear.name}"
    action="redeploy"/>
    </target>

    <target name="all" depends="undeploy,deploy"/>


    </project>

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

    Commit

    then while in /home/svn/working/project2/BuildEnvironmentEAR type:

    [svn@s15382406 BuildEnvironmentEAR]$ svn update
    A dbuild.xml
    Updated to revision 63.

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




    ==================
    lets try the deployment manually

    ant -f ./dbuild.xml

    BUILD FAILED
    /home/svn/working/project2/BuildEnvironmentEAR/dbuild.xml:45: weblogic.Deployer$DeployerException: weblogic.deploy.api.tools.deployer.DeployerException: java.net.URISyntaxException: Illegal character in authority at index 5: t3://${weblogic.adminhost}:7001

    We did not provide properties file containing the weblogic login details





    # An administrator user that can deploy to the domain.
    weblogic.user: weblogic
    weblogic.password: v3Interact1ve

    #Hosts as used in deployments
    weblogic.adminhost: linux.veinteractive.net





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

    add to project then commit then update the linux folder with svn update

    result:





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

    ant -f ./dbuild.xml

    BUILD FAILED
    /home/svn/working/project2/BuildEnvironmentEAR/dbuild.xml:38: java.lang.IllegalArgumentEx ception: The file, '/home/svn/working/project2/BuildEnvironmentEAR/dist/EnvironmentWebEAR ', does not exist.

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


    [svn@s15382406 BuildEnvironmentEAR]$ ant -f ./dbuild.xml
    Buildfile: ./dbuild.xml
    [echo] weblogic.user=weblogic
    [echo] weblogic.password=v3Interact1ve
    [echo] weblogic.adminhost=linux.veinteractive.net
    [echo] ear.name=EnvironmentWebEAR
    [echo] ear.src.name=dist/EnvironmentWebEAR
    [echo] ear.name=EnvironmentWebEAR

    undeploy:
    [wldeploy] weblogic.Deployer -verbose -noexit -name EnvironmentWebEAR -adminurl t3://linux.veinteractive.net:7001 -user weblogic -password ******** -undeploy
    [wldeploy] weblogic.Deployer invoked with options: -verbose -noexit -name EnvironmentWebEAR -adminurl t3://linux.veinteractive.net:7001 -user weblogic -undeploy
    [wldeploy] <Apr 23, 2010 11:44:25 PM GMT> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating undeploy operation for application, EnvironmentWebEAR [archive: null], to configured targets.>

    BUILD FAILED
    /home/svn/working/project2/BuildEnvironmentEAR/dbuild.xml:45: weblogic.management.ManagementException: [Deployer:149001]No application named 'EnvironmentWebEAR' exists for operation undeploy

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

    We forgot to specify the target, the default is to undeplly foirst, but since it has never been deployed we cannot undeploy. By setting the target as deploy we only deploy.

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

    ant -f ./dbuild.xml deploy

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



    BUILD FAILED
    /home/svn/working/project2/BuildEnvironmentEAR/dbuild.xml:38: weblogic.management.ManagementException: [Deployer:149003]Unable to access application source information in '<!DOCTYPE HTML PUBLIC "-/W3C/DTD HTML 4.0 Draft/EN">/app/EnvironmentWebEAR.ear' for application 'EnvironmentWebEAR.ear'. The specific error is: No application files exist.

    this error was due to the fact we have IBM specific deployment descriptors in the EAR project lets tidy thing up.

    ===========


    Bascially our application.xml had been built in JDK1.4 which as a little old.


    <?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>
    EnvironmentWebEAR</display-name>
    <module id="WebModule_1219184422718">
    <web>
    <web-uri>EnvironmentWeb.war</web-uri>
    <context-root>env</context-root>
    </web>
    </module>
    </application>

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

    It should have been, lets change it and commit and update etc..


    <?xml version="1.0" encoding="ASCII"?>
    <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" version="5">
    <display-name>EnvironmentWebEAR</display-name>
    <module>
    <web>
    <web-uri>EnvironmentWeb.war</web-uri>
    <context-root>env</context-root>
    </web>
    </module>
    </application>

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

    /home/svn/working/project2/EnvironmentWebEAR

    svn update


    [svn@s15382406 EnvironmentWebEAR]$ svn update
    D EarContent/META-INF/ibmconfig >> I Deleted the ibm stuff we did not need.We will address this when we get to a WebSphere 7 Deployment.
    U EarContent/META-INF/application.xml
    Updated to revision 67.

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

    We also had the same problem with the web.xml and fixed

    OLD

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.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/web-app_2_4.xsd">
    <display-name>
    EnvironmentWeb</display-name>
    <servlet>
    <description>
    </description>
    <display-name>
    GetEnvVar</display-name>
    <servlet-name>GetEnvVar</servlet-name>
    <servlet-class>
    com.webspheretools.GetEnvVars</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>GetEnvVar</servlet-name>
    <url-pattern>/getenvvar</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    </web-app>


    NEW

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.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/web-app_2_4.xsd">
    <display-name>HR Application</display-name>

    <servlet>
    <description>
    </description>
    <display-name>GetEnvVar</display-name>
    <servlet-name>GetEnvVar</servlet-name>
    <servlet-class>com.webspheretools.GetEnvVars</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>GetEnvVar</servlet-name>
    <url-pattern>/getenvvar</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    </web-app>


    /home/svn/working/project2/EnvironmentWeb

    svn update

    ==================
    /home/svn/working/project2/BuildEnvironmentEAR

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


    BUILD FAILED
    /home/svn/working/project2/BuildEnvironmentEAR/dbuild.xml:38: weblogic.management.ManagementException: [Deployer:149003]Unable to access application source information in '<!DOCTYPE HTML PUBLIC "-/W3C/DTD HTML 4.0 Draft/EN">/app/EnvironmentWebEAR.ear' for application 'EnvironmentWebEAR.ear'. The specific error is: No application files exist.

    the problem was the upload folder contained the old EAr file and it was getting confused. Not sure why may need to look at finding how the WLDeploy ant task can purge the upload folder first. I figured it out 5 mins later...it was because earlier in the day I had manually deployed the application by hand to the linux server and forgot to remove it.

    the upload folder was:

    /var/apps/weblogic10/user_projects/domains/VeInteractive/servers/AdminServer/upload

    I just used rm -Rf <my ear file>

    Ran again the dbuild.xml command above and it worked

    [wldeploy] Target state: deploy completed on Server AdminServer

    [wldeploy] Target Assignments:
    [wldeploy] + EnvironmentWebEAR.ear AdminServer
    [wldeploy] [ServerConnectionImpl.close():331] : Closing DM connection
    [wldeploy] [ServerConnectionImpl.close():351] : Unregistered all listeners
    [wldeploy] [ServerConnectionImpl.closeJMX():371] : Closed JMX connection
    [wldeploy] [ServerConnectionImpl.closeJMX():383] : Closed Runtime JMX connection
    [wldeploy] [ServerConnectionImpl.closeJMX():395] : Closed Edit JMX connection

    BUILD SUCCESSFUL
    Total time: 4 seconds



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

    Note you can use:svn update * in a parent directory to update all folders

    drwxrwxr-x 6 svn svn 4096 Apr 23 23:29 EnvironmentWeb
    drwxrwxr-x 5 svn svn 4096 Apr 23 23:29 EnvironmentWebEAR
    drwxrwxr-x 5 svn svn 4096 Apr 24 00:15 BuildEnvironmentEAR
    [svn@s15382406 project2]$ svn update *
    At revision 71.
    U EnvironmentWeb/src/com/webspheretools/GetEnvVars.java
    Updated to revision 71.
    Updated to revision 71.

    ===============================
    create a build.sh for manual build testing

    [svn@s15382406 BuildEnvironmentEAR]$ echo ant -f ubuild.xml > build.sh
    [svn@s15382406 BuildEnvironmentEAR]$ chmod 775 ./build.sh

    Create a deploy.sh script

    echo ant -f ./dbuild.xml deploy > deploy.sh
    chmod 775 ./deploy.sh

    Re-run deploy via ./deploy.sh

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

    Lets see it running


    We can see now we have fixed the content type issue and it renders as HTML. the code is not that fancy, but it is a great tool. We have proven we build and deploy from changes made to SVN code.

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

    Lets log into Hudson and create a deployment job to automate the process








    Note I no longer use spaces, this is so later we can start to use the Hudon workdpace build area which keeps build numbers and xml reports locally on linux. currently We have been using a custom workspace location /home/svn/working/project2/BuildEnvironmentEAR. Hudson work in /home/weblogic/hudson



    We can look at this another day.

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

    When we create our job we are going to use the hudson SVN plugin to call an update, but since our build project is on the same level as the EAR and WAR we need to update the entire Java_Training folder, this is not so good, but works (updates all projects even the ones we are not using). We could just make scripts to call specfic SVN updates and not use this plugin.











    Add the deployment Ant task

    etc





    Save and run






    Forgot to set custom workspace










    Save


    Re run










    This is the problem with a mixed project when SVN is not in the format to create appropriate paths in sync with SVN repository

    So what we need to do is stop the SVN update via the plugin for now and we will make our own scripts to to do the update. ie build.sh etc. For my HR Application example I did things a little differently. Long story short, I broke my won rules and cheated as it was more about the building of the app and testing oracle than auto deployment along with good simple projet planning.

    We still have many steps, but we are redundant steps each time I do this. Essentially this I only day two of using hudson on our Liux Server.

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

    Modified the BuildAndDeployEnvironmentEAR job to use the build,sh script as follows

    svn update ../*
    ant -f ubuild.xml
    ~


    ================
    Turn off SVN plugin










    Re-run


    Started by user admin
    [BuildEnvironmentEAR] $ /bin/sh -xe /tmp/hudson5515947501719934476.sh
    + ./build.sh
    svn: Can't open file '../BuildEnvironmentEAR/.svn/lock': Permission denied
    Buildfile: ubuild.xml
        [echo] ------------------ Properties ------------------------------
        [echo] root=/home/svn/working/project2/BuildEnvironmentEAR
        [echo] EARBasePath=/home/svn/working/project2/BuildEnvironmentEAR/../EnvironmentWebEAR
        [echo] WARBasePath=/home/svn/working/project2/BuildEnvironmentEAR/../EnvironmentWeb
        [echo] lib.dir=/home/svn/working/project2/BuildEnvironmentEAR/../EnvironmentWeb/lib
        [echo] src.dir=/home/svn/working/project2/BuildEnvironmentEAR/../EnvironmentWeb/src
        [echo] pages.dir=/home/svn/working/project2/BuildEnvironmentEAR/../EnvironmentWeb/WebContent
        [echo] ----------------------------------------------------------

    clean:
        [echo] === CLEAN ===
      [delete] Deleting directory /home/svn/working/project2/BuildEnvironmentEAR/temp

    BUILD FAILED
    /home/svn/working/project2/BuildEnvironmentEAR/ubuild.xml:48: Unable to delete directory /home/svn/working/project2/BuildEnvironmentEAR/temp

    Total time: 0 seconds
    Finished: FAILURE

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

    Problem the working folders are owned by svn:svn and need to be sv:dev as the weblogiuc usr that hudosn runs as is not in the svn group



    Need to chown -R svn:dev project2




    After a few builds we got there.

    OK now for Part 2. Lets make a web service

Get my WebSphere Application Server course here >> http://www.themiddlewareshop.com/products/

Steve Robinson - IBM Champion 2013

About Me

Steve Robinson has been working in IT for over 20 years and has provided solutions for many large-enterprise corporate companies across the world. Steve specialises in Java and Middleware.

In January 2013, I was awarded the prestigous 'IBM Champion' accolade.


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

Other Categories