Click on the images to view them full size!
Step 14 - Packaging the Application
To deploy an EJB application in any application server, we must package it as an .ear file. An .ear file contains the enterprise bean modules, the deployment descriptors, mapping information, any container specific descriptor files, and dependent wars and jars. In our case, WSAD has already created the Websphere specific descriptor fies for us.
We can either manually create an .ear fie by assembling these files using java jarring, or choose Apache Ant to do the task for us. using the Ant commands, we can automate the whole compiling, deployment code generation and archiving process to a one click job. Ant can do a lot more like, checking out a project from the repository(like CVS) and do real deployment on the server. Let's start by creating an Simple Project in WSAD. Name it EmployeeBuild.
Now, create a new file and name it build.xml. Copy the following ant script to it.
<project name="EmployeeTest Ant" default="Total" basedir=".">
<!-- Set global properties -->
<property name="workspace.dir" value="D:/IBM/WebSphere Studio/Application Developer/WS" />
<property name="project.ear" value="EmployeeEAR" />
<property name="project.ejb" value="EmployeeEJB" />
<property name="project.war" value="EmployeeWeb" />
<property name="type" value="incremental" />
<property name="debug" value="true" />
<property name="source" value="false" />
<property name="meta" value="false" />
<property name="noValidate" value="false" />
<property name="dist" value="${workspace.dir}/EmployeeDistDir" />
<target name="init">
<!-- Create the time stamp -->
<tstamp />
<!-- Create the dist directory where the archive files will be placed -->
<mkdir dir="${dist}" />
<echo message="Directory Created " />
</target>
<!-- START ProjectEjb -->
<target name="getProjectDataEjb">
<getProjectData Basedir="${workspace.dir}/${project.ejb}" />
<echo>grtProjectData ${workspace.dir}/${project.ejb}</echo>
</target>
<target name="deployEjb" depends="getProjectDataEjb">
<!-- Generates deployed code for the EJBs -->
<ejbDeploy EJBProject="${project.ejb}" NoValidate="${noValidate}" />
</target>
<target name="buildEjb">
<!-- Builds the EJB project -->
<projectBuild ProjectName="${project.ejb}" BuildType="${type}" DebugCompilation="${debug}" />
</target>
<!-- END -->
<!-- START ProjectWeb_1 -->
<target name="getProjectDataWeb">
<getProjectData Basedir="${workspace.dir}/${project.war}" />
<echo>grtProjectData ${workspace.dir}/${project.war}</echo>
</target>
<target name="buildWar" depends="getProjectDataWeb">
<!-- Builds the WAR project -->
<projectBuild ProjectName="${project.war}" BuildType="${type}" DebugCompilation="${debug}" />
</target>
<!-- END -->
<!-- START ProjectEar -->
<target name="getProjectDataEar">
<getProjectData Basedir="${workspace.dir}/${project.ear}" />
<echo>grtProjectData ${workspace.dir}/${project.ear}</echo>
</target>
<target name="buildEar" depends="getProjectDataEar">
<!-- Builds the EAR project -->
<projectBuild ProjectName="${project.ear}" BuildType="${type}" DebugCompilation="${debug}" />
</target>
<!-- END -->
<target name="exportEjb" depends="init">
<!-- Exports the EJB JAR -->
<echo>Test Message --- Jim</echo>
<ejbExport EJBProjectName="${project.ejb}" EJBExportFile="${dist}/${project.ejb}.jar" ExportSource="${source}" overwrite="true" />
</target>
<target name="exportWar1" depends="init">
<!-- Exports the WAR file -->
<warExport WARProjectName="${project.war}" WARExportFile="${dist}/${project.war}.war" ExportSource="${source}" overwrite="true" />
</target>
<target name="exportEar" depends="init">
<!-- Exports the EAR file -->
<earExport EARProjectName="${project.ear}" EARExportFile="${dist}/${project.ear}.ear" ExportSource="${source}" IncludeProjectMetaFiles="${meta}" overwrite="true" />
<echo message="Exported EAR" />
</target>
<!--Here importProjects, as first param -->
<target name="buildAll" depends="deployEjb,buildEjb,buildWar,buildEar">
<!-- Builds all projects -->
<echo message="Built all projects" />
</target>
<target name="exportAll" depends="exportEjb,exportWar1,exportEar">
<!-- Exports all files -->
<echo message="Exported all files" />
</target>
<target name="Total" depends="buildAll,exportAll">
<!-- Buidl all projects and exports all files -->
<echo message="Total finished" />
</target>
<target name="clean">
<!-- Delete the output files -->
<delete file="${dist}/${project.ejb}.jar" failOnError="false" />
<delete file="${dist}/${project.war}.war" failOnError="false" />
<delete file="${dist}/${project.ear}.ear" failOnError="false" />
</target>
</project>
The code is self-explanatory. 'Total" is our default target here. It depends on 2 tasks. 'BuildAll' and 'ExportAll'. 'BuildAll' invokes tasks for deployment code generation for EJB and builds all the projects. 'ExportAll' exports the built projects to wars jars and ears.
Make sure to change the 'workspace.dir' property to match your enviornment.
WSAD comes with Ant library, so yuo wont have to download and copy the Ant jar file to your classpath to run an Ant Script. To run our build.xml Ant in WSAD, right-click the file in Project Explorer and select 'Run Ant..'. This will show us the available ant tasks to run. Our default task 'Total' will be selected by default.
Here you may change the order or opt to execute a different task. In our case, just click the Run button, and you will see the messages scrolling up in the console. When finished, you will see a confirmation message at the bottom of the console.
That's it. If the build process was successful, our .ear and other files would be created in the destination Directoriy.
Step 15 - Deployment Process
This section assumes that you have access to the Admin Console of a WebSphere Application Server or Integrated Solutions Console or Network Deployment Manager.
Remember we configured a JAAS entry (Step 5) and a Datasource (Step 6) on the TestServer. The same needs to be performed as an enviornment setup on the Application Server as well.
The JAAS entry con be configured in the Security Tab. Select Secure Administration, applications and infrastructure.
Under the Authentication section, and configure the entry under Java Authentication and Autherization Service->J2C Authentication Data.
The Datasource can be configured under Resources->DataSources->JDBC
Make sure to save the configuration changes each time you make a new entry.
Click on the Save link that appears on the page, each time after you make a change to Save the changes.
That's all about the configurations. Now we need to do the actual deployment of our .ear on the Application Server. Click on Applications->Install New Application.
Selct EmployeeEAR.ear from the EmployeeDistDir, where the ear was created by our Ant script. Click Next. Accept all defaults in the installation options page and Click Next. In the Map modules to servers page, select the servers on which you would like to install the application (In a clustered enviornment, you might have to choose multiple nodes and servers) and select both EmployeeEJB and EmployeeWeb to deploy.
Click Next. Click Finish in the Summary page. This will take a while to install the application. When done, the page displays a Successful message and asks you to save the configuration changes. Click on the Save link to do so, and we are done with the deployment.
Now the application got deployed, but it's not started yet. To start the application, go to Applications->Enterprise Applications. Select EmployeeEAR and click the start button.
Please note that, if you are deploying the application in a clustered enviornment, you will have to start the cluster/application servers under Servers menu before starting up the application.
Now, we need to verify that our application really works. As we did with the test server, we will try to invoke the Entity bean through our servlet, for which we created the EmployeeWeb Project. Now, to access the index.html page of our web application, you must know the port on which the server is listening for HTTP requests. You must have noted it when performing the Application Server installation. If you don't have this information, go to Application servers > server1 > Ports > WC_defaulthost to get the Port for the Default Host.
Once you are ready, type in http://<yourserver>:<yourport>/EmployeeWeb/ (http://localhost:9080/EmployeeWeb/ in my case). Hopefully, you get the below page.
Type in the Employee ID of Aishwarya Rai and check if your Entity bean brings in the result.
If you encounter a problem, look for the Websphere SystemOut and SystemErr logs to find the cause and search in Google to find a solution. Do let me know if you cant resolve it. I will also try to search it out for you.
The workspace of an improved version of these projects is available here.
And the .ear is here.
Go to : Part 1Part 2Part 3Part 4Part 5Part 6
1 comment:
Sorry for my bad english. Thank you so much for your good post. Your post helped me in my college assignment, If you can provide me more details please email me.
Post a Comment