Pages - Menu

Deployment : Creating War file and directory structure

Saturday, July 27, 2013

WAR Directory Structure
    

Develop your Web Application within a specified directory structure so that it can be archived and deployed on WebLogic Server or another J2EE-compliant server. All servlets, classes, static files, and other resources belonging to a Web Application are organized under a directory hierarchy. The root directory of this hierarchy defines the document root of your Web Application. All files under this root directory can be served to the client, except for files under the special directory WEB-INF, located under the root directory.
********************************************************************************************************
Place private files in the WEB-INF directory, under the root directory. All files under WEB-INF are private, and are not served to a client.
DefaultWebApp/
Place your static files, such as HTML files and JSP files in the directory that is the document root of your Web Application. In the default installation of WebLogic Server, this directory is calledDefaultWebApp, under user_domains/mydomain/applications.
DefaultWebApp/WEB-INF/web.xml
The Web Application deployment descriptor that configures the Web Application.
DefaultWebApp/WEB-INF/weblogic.xml
The WebLogic-specific deployment descriptor file that defines how named resources in the web.xml file are mapped to resources residing elsewhere in WebLogic Server. This file is also used to define JSP and HTTP session attributes.
DefaultWebApp/WEB-INF/classes
Contains server-side classes such as HTTP servlets and utility classes.
DefaultWebApp/WEB-INF/lib
Contains JAR files used by the Web Application, including JSP tag libraries.
**********************************************************************************
Creating Web Applications: Main Steps
Here are the main steps for creating a Web application:
  1. Create the HTML pages and JavaServer Pages (JSPs) that make up the Web interface of the Web application. Typically, Web designers create these parts of a Web application.

  2. Write the Java code for the servlets and the JSP taglibs referenced in JSPs. Typically, Java programmers create these parts of a Web application.
  3. Compile the servlets into class files.
  4. Arrange the resources (servlets, JSPs, static files, and deployment descriptors) in the prescribed directory format. ( as above in red )
  5. Create the web.xml and weblogic.xml deployment descriptors.
    The web.xml file defines each servlet and JSP page and enumerates enterprise beans referenced in the Web application. The weblogic.xml file adds additional deployment information for WebLogic Server.
    Create the web.xml and weblogic.xml deployment descriptors manually or using WebLogic Builder. 

  6. Package the HTML pages, servlet class files, JSP files, web.xml file, and weblogic.xml file into a WAR file.
    Create a Web application staging directory and save the JSPs, HTML pages, and multimedia files referenced by the pages in the top level of the staging directory.
    Store compiled servlet classes, taglibs, and, if desired, servlets compiled from JSP pages are stored under a WEB-INF directory in the staging directory. When the Web application components are all in place in the staging directory, you create the WAR file with the JAR command.
  7. Auto-deploy the WAR file on WebLogic Server for testing purposes.
    While you are testing the Web application, you might need to edit the Web application deployment descriptors. You can do this manually or use WebLogic Builder.
  8. Deploy the WAR file on the WebLogic Server for production use or include it in an Enterprise ARchive (EAR) file to be deployed as part of an enterprise application.

Application Deployment as a Library

J2EE library support in WebLogic Server 9.x onwards provides an easy way to share one or more J2EE modules or JAR files among multiple Enterprise Applications. 


A J2EE library is a stand-alone J2EE module, multiple J2EE modules packaged in an Enterprise Application (EAR), or a plain JAR file that is registered with the J2EE application container upon deployment. 


After a J2EE library has been registered, you can deploy Enterprise Applications that reference the library. 


Each referencing application receives a copy of the shared J2EE library module(s) on deployment, and can use those modules as if they were packaged as part of the application itself.


you need to select "Install this application as a Library" during deployment then target it to the servers where deployed applications need to access these library files.


Quick Deployment using WLST

You can use WLST to quickly deploy an Application  File in a Weblogic Server.

What do you need ?

  • The ear/war/rar/jar  file ( uploaded to a directory in the target WebLogic Server )
  • A simple WLST script
  • Credentials for the Weblogic Server ( preferrably, the weblogic user ).


  • Write a simple WLST Script to do your work and save it as "deploy.py"
print '*** WEBLOGIC : START ***'
print 'connecting to admin server....'
connect( 'weblogic', 'webl0gic', 't3://localhost:7001', adminServerName='AdminServer' )
print 'stopping and undeploying ....'
stopApplication('shoppingcart')
print 'deploying....'
deploy('shoppingcart', 'c:/shoppingcart.war', targets='AdminServer')
startApplication('shoppingcart')
print 'disconnecting from admin server....'
disconnect()
exit()
print '*** WEBLOGIC : STOP ***'

  • Open a Terminal Window / Command Prompt
  • Run the setDomainEnv.sh ( or setDomainEnv.bat ) script to set the required environment variables under <domain>/bin.
  • run :-  java weblogic.WLST deploy.py

output -

*************************************************************************************************************



java weblogic.WLST sc

ript.py

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

*** WEBLOGIC : START ***
connecting to admin server....
Connecting to t3://localhost:7001 with userid weblogic ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'bas
e_domain'.

Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.

stopping and undeploying ....
Stopping application shoppingcart.
<Oct 20, 2010 2:10:43 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiat
ing stop operation for application, shoppingcart [archive: null], to AdminServer
 .>
Completed the stop of Application with status completed
Current Status of your Deployment:
Deployment command type: stop
Deployment State       : completed
Deployment Message     : no message
deploying....
Deploying application from c:\shoppingcart.war to targets AdminServer (upload=fa
lse) ...
<Oct 20, 2010 2:10:44 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiat
ing deploy operation for application, shoppingcart [archive: c:\shoppingcart.war
], to AdminServer .>
.Completed the deployment of Application with status completed
Current Status of your Deployment:
Deployment command type: deploy
Deployment State       : completed
Deployment Message     : no message
Starting application shoppingcart.
<Oct 20, 2010 2:10:48 PM IST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiat
ing start operation for application, shoppingcart [archive: null], to AdminServe
r .>
.Completed the start of Application with status completed
Current Status of your Deployment:
Deployment command type: start
Deployment State       : completed
Deployment Message     : no message
disconnecting from admin server....
Disconnected from weblogic server: AdminServer

Exiting WebLogic Scripting Tool.

<Oct 20, 2010 2:10:51 PM IST> <Warning> <JNDI> <BEA-050001> <WLContext.close() w
as called in a different thread than the one in which it was created.>
************************************************************************************************************

Weblogic Side by Side Deployment

Welogic server Side by side deployment

Keywords : weblogic side by side deployment, side by side deployment in weblogic, deployment, weblogic deployment

Weblogic Server supports a nice feature called side-by-side deployment (or versioned deployment). This function is extremely usefull when you need to deploy a new version of an application and still keep the old one up and running. So the running instances will still use the current version and all new instances will be able to invoke the new deployed version of the application. 

As soon as all the sessions who’re using the old version of the application are expired, Weblogic will recognize it and will deactivate the old version. So at this moment only the new deployed version is active and all new sessions will make us of it.


So how does this work ?

[A].1 . You could either use command line to deploy the application and specify the versionnumber on deployment as one of   
           the parameters
[B].1.   you can use the manifest.mf file and deploy from console


********************************** 
[A].1 -> From command line
********************************* 


Deploy a web application version 1 with below command ( i am deploying on Admin server )


java weblogic.Deployer -adminurl t3://localhost:7001 -username weblogic -password webl0gic -name VersionedApp  -targets AdminServer -deploy -source C:\shoppingcart.war -appversion version1


you will see application deployed with as version1.










Now redeploy the application as version 2 with below commands


java weblogic.Deployer -adminurl t3://localhost:7001 -username weblogic -password webl0gic -name VersionedApp -targets AdminServer -redeploy -source C:\shoppingcart.war  -appversion version2 









you will see same application deployed with as version2.


go ahead and delete the old application with status as retired.


************************
[B].1 From Console
************************
Edit to manifest file located in  META-INF and add the next on a new row : ‘WebLogic-Application-Version: v1′


    manifest






Package the service and deploy it in the console

Deployment
  1. Go to the Weblogic Console > Deployments. Click ‘Lock & Edit’ and in the deployments part click Install
  2. Select the just created archiveinstall-1
  3. Install this deployment as an application
  4. Optional Settings. And in here we will see the ‘Archive Version’ of our application. Change the name to ‘MyService’ and leave the rest on default valueinstall-2
If you look in the list of deployments we will see our application is labeled with a version indication (v1).deployment1
The current version is still active.

Now create a new version of the application and change the v1 in the manifest file to v2, and package it.

Update Deployment
  1. Go to the Weblogic Console > Deployments. Click ‘Lock & Edit’, select the application we want to update (MyService) and in the deployments part click Update
  2. Click Change Path of the source path and select the just created archive (v2), the application will be deployed as version v2
If we now look in the list of deployments, we will see 2 versions of our application deployed.

deployment2

Version v1 gets status ‘Retired’ and the new version v2 will get status ‘Active’.

Deployment : war, ear and jar files

Deployment : war, ear and jar files

Difference between ear, war and jar files.

Enterprise Application ( .ear )

An Enterprise Application consists of one or more of the following J2EE applications or modules:
  • Web applications
  • Enterprise Java Beans (EJB) modules
  • Resource Adapter modules
An Enterprise Application is packaged as an archive file with an .ear extension
you can say it's a collection of war & jar files

Web Application ( .war )
Web application always includes the following files:
  • A servlet or JSP page, along with any helper classes.
  • web.xml deployment descriptor, a J2EE standard XML document that configures the contents of a WAR file.
Web applications may also contain JSP tag libraries, static .html and image files, supporting classes and .jar files, and a weblogic.xml deployment descriptor, which configures WebLogic Server-specific elements for Web applications. 

Enterprise JavaBean ( .jar )

Enterprise JavaBeans (EJBs) are reusable Java components that implement business logic and enable you to develop component-based distributed business applications. EJB modules are packaged as archive files having a .jar extension.


Summary

Deployment units that are packaged using the jar utility have a specific file extension depending on the type:
  • EJBs and client archives are packaged as .jar files.
  • Web applications are packaged as .war files.
  • Resource adapters are packaged as .rar files.
  • Enterprise applications are packaged as .ear files, and can contain other Java EE modules such as EJBs, JDBC, JMS, Web Applications, and Resource Adapters.
  • Web Services can be packaged either as .war files or as .jar files, depending on whether they are implemented using Java classes or EJBs. Typically, the .war or .jar files are then packaged in an Enterprise Application .ear file.
  • Java EE libraries are packaged either as an Enterprise Application (.ear file) or as a standard Java EE module.
  • Client applications and optional packages are packaged as .jar files.

Deployment : Archive & Exploded Format

Archive Files
In most production environments, you will receive a deployable module as an archive file. An archive file is a single file that contains all of a J2EE module's classes, static files, directories, and deployment descriptor files. Archive files are created by using the jar utility to package the top-level directory of a J2EE module.
Modules that are packaged using the jar utility have specific file extension depending on the module type:
  • EJBs are packaged as .JAR files.
  • Web Applications are packaged as .WAR files.
  • Resource Adapters are packaged as .RAR files.
  • Enterprise Applications are packaged as .EAR files.
In most cases, you will deploy the archive file itself with no additional preparation.
Exploded Archive Directories
An exploded archive directory contains the same files and directories as a jar archive. However, the files and directories reside directly in your file system and are not packaged into a single archive file using the jar utility.
You may need to deploy a module as an exploded archive directory, rather than a single archive file, in the following circumstances:
  • You are deploying an EJB, Web Application, or Enterprise Application that performs direct file system I/O. In this case, the components that perform the I/O operations should have a physical filesystem directory in which to work.
  • You are deploying a Web Application or Enterprise Application that contains static files that you will periodically update. In this case, it is more convenient to deploy the module as an exploded directory, because you can update and refresh the static files without editing the archive.

How to increase default work manager threads

The default workmanager, as its name tells, is the workmanager defined by default.
Thus, all applications deployed on WLS will use it. The default workmanager belongs to a threadpool.

As the initial threadpool comes with only five threads, that's not much.














































If your application has to face a large number of hits, you may want to start with more than that. 
Well, that's quite easy. You've got two ways to do so.

1) Modifying the config.xml
Just add the following line(s) in your server definition :

<server>
<name>AdminServer</name>
<self-tuning-thread-pool-size-min>100</self-tuning-thread-pool-size-min>
<self-tuning-thread-pool-size-max>200</self-tuning-thread-pool-size-max>
[...]
</server>
2) Adding some JVM parameters

Personally, that's my favorite option since I don't like when people go in a generated config file and mess up with tags. If you're sure of what you're doing, that's ok, but it's safer the following way :

add the following option in your command line : 
-Dweblogic.threadpool.MinPoolSize=100


Observing the result






Performance Tuning Part - 3 : Work Managers

1]. WebLogic Server allows you to configure how your application prioitizes the   
     execution of its work. 

2]. Based on rules you define and by monitoring actual runtime performance, WebLogic   
     Server can optimize the performance of your application and maintain service level  
     agreements. 

3].  You define the rules and constraints for your application by defining a Work Manger  
      and applying it either globally to WebLogic Server domain or to a specifi  
      application component.

4]. In WebLogic Server 9.0 there is a single thread pool, in which all types of work are  
     executed. WebLogic Server prioritizes work based on rules you define, and run-
     time metrics, including the actual time it takes to execute a request and the rate at
     which requests are entering and  leaving the pool.

5]. The common thread pool changes its size automatically to maximize
      throughput. The queue monitors throughput over time and based on history,
      determines whether to adjust the thread count. 

     For example, if historical throughput statistics indicate that a higher thread count  
     increased  throughput, WebLogic increases the thread count. Similarly, if statistics
     indicate that fewer threads did not reduce throughput, WebLogic decreases the  
     thread count. This new strategy makes it easier for administrators to allocate
     processing resources and manage performance, 
     avoiding the effort and complexity involved in configuring, monitoring, and tuning
      custom executes queues.

6]. Administrators can configure a set of scheduling guidelines and associate
     them with one or more applications, or with particular application components.

For example,
  
you  can associate one set of scheduling guidelines for one application, and another  
  set of guidelines for other application. At run-time, WebLogic Server uses these
  guidelines to assign  pending work and enqueued requests to execution threads.


7] .

Work Managers can be configured at the domain level, application level, and module level in one of the following configuration files:
  • config.xml—Work Managers specified in config.xml can be assigned to any application, or application component, in the domain. You can use the Administration Console to define a Work Manager.
  • weblogic-application.xml—Work Managers specified at the application level in can be assigned to that application, or any component of that application.
  • weblogic-ejb-jar.xml or weblogic.xml—Work Managers specified at the component-level can be assigned to that component.
  • weblogic.xml—Work Managers specified for a Web Application.
Work Manager Stanza
<work-manager>
<name>highpriority_workmanager</name>
   <fair-share-request-class>
      <name>high_priority</name>
      <fair-share>100</fair-share>
   </fair-share-request-class>
   <min-threads-constraint>
      <name>MinThreadsCountFive</name>
      <count>5</count>
</work-manager>
To reference the Work Manager listed above in the dispatch policy of a Web Application, add the below code into the Web Application's web.xml file:
Referencing the Work Manager in a Web Application
<init-param>
   <param-name>dispatch-policy</param-name>
   <param-value>highpriority_workmanager</param-value>
</init-param>

8]  To manage work in your applications, you define one or more of the following Work Manager 
     components:

  • Fair Share Request Class:
  • Response Time Request Class:
  • Min Threads Constraint:
  • Max Threads Constraint:
  • Capacity Constraint
  • Context Request Class:


  • fair-share-request-class—Specifies the average percentage of thread-use time required to process requests.
For example, assume that WebLogic Server is running two modules. The Work Manager for ModuleA specifies a fair-share-request-class of 80 and the Work Manager for ModuleB specifies afair-share-request-class of 20.
During a period of sufficient demand, with a steady stream of requests for each module such that the number requests exceed the number of threads, WebLogic Server will allocate 80% and 20% of the thread-usage time to ModuleA and ModuleB, respectively.
  • response-time-request-class—This type of request class specifies a response time goal in milliseconds. Response time goals are not applied to individual requests. Instaead, WebLogic Server computes a tolerable waiting time for requests with that class by subtracting the observed average thread use time from the response time goal, and schedules schedule requests so that the average wait for requests with the class is proportional to its tolerable waiting time.

For example, given that ModuleA and ModuleB in the previous example, have response time goals of 2000 ms and 5000 ms, respectively, and the actual thread use time for an individual request is less than its response time goal. During a period of sufficient demand, with a steady stream of requests for each module such that the number requests exceed the number of threads, and no "think time" delays between response and request, WebLogic Server will schedule requests for ModuleA and ModuleB to keep the average response time in the ratio 2:5. The actual average response times for ModuleA and ModuleB might be higher or lower than the response time goals, but will be a common fraction or multiple of the stated goal. For example, if the average response time for ModuleA requests is 1,000 ms., the average response time for ModuleB requests is 2,500 ms.
  • context-request-class—This type of request class assigns request classes to requests based on context information, such as the current user or the current user's group.

  • max-threads-constraintThis constraint limits the number of concurrent threads executing requests from the constrained work set. The default is unlimited. For example, consider a constraint defined with maximum threads of 10 and shared by 3 entry points. The scheduling logic ensures that not more than 10 threads are executing requests from the three entry points combined.
max-threads-constraint can be defined in terms of a the availability of resource that requests depend upon, such as a connection pool.
max-threads-constraint might, but does not necessarily, prevent a request class from taking its fair share of threads or meeting its response time goal. Once the constraint is reached the server does not schedule requests of this type until the number of concurrent executions falls below the limit. The server then schedules work based on the fair share or response time goal.
  • min-threads-constraintThis constraint guarantees a number of threads the server will allocate to affected requests to avoid deadlocks. The default is zero. A min-threads-constraint value of one is useful, for example, for a replication update request, which is called synchronously from a peer.

min-threads-constraint might not necessarily increase a fair share. This type of constraint has an effect primarily when the server instance is close to a deadlock condition. In that case Then, however, it the constraint will cause WebLogic Server to schedule a request from a even if requests in the service class have gotten more than its fair share recently.
  • capacityThis constrain causes the server to reject requests only when it has reached its capacity. The default is zero. Note that the capacity includes all requests, queued or executing, from the constrained work set. Work is rejected either when an individual capacity threshold is exceeded or if the global capacity is exceeded. This constraint is independent of the global queue threshold.
 

Archives

Blogger news

Blogroll

Most Reading