Presentation is loading. Please wait.

Presentation is loading. Please wait.

C HAPTER 11 D EPLOYING YOUR WEB APP. WAR FILE A WAR file is simply a snapshot of your web app structure, in a nice portable, compressed form (it is really.

Similar presentations


Presentation on theme: "C HAPTER 11 D EPLOYING YOUR WEB APP. WAR FILE A WAR file is simply a snapshot of your web app structure, in a nice portable, compressed form (it is really."— Presentation transcript:

1 C HAPTER 11 D EPLOYING YOUR WEB APP

2 WAR FILE A WAR file is simply a snapshot of your web app structure, in a nice portable, compressed form (it is really just a JAR file). You jar up your entire web app structure and give it a.war extension. Thus instead of copy static web pages, JSP pages, servlets, and web.xml separately to appropriate locations of Tomcat for deployment, we can simply copy this single WAR file to tomcat’s webapps directory.

3 WAR FILE Tomcat will be responsible for unpack the WAR file and create a corresponding application context/directory and put all extracted files there. In Tomcat, the name of the WAR file becomes the web app name. – That is, if you drop the file lab8.war to Tomcat’s webapps directory, a new directory called lab8 will be created under the webapps directory.

4 WAR FILE If you re-deploy the application by dropping an updated WAR file to tomcat’s webapps directory, tomcat will first remove the application context/directory, then extract files from the updated WAR file, and re-create the application context/dir for the application. Another advantage: You do not have to restart your Tomcat server after the re-deployement even if you have servlets inside your application If you want to un-deploy the application, simply delete the WAR file from tomcat’s webapps directory (You do not need to remove the unpacked directory, tomcat will be able to automatically remove it)

5 What a deployed WAR file looks like Note: META-INF and MANIFEST.MF under it are automatically generated and MANIFEST.MF is used for specifying optional libraries, e.g., the libraries the container cannot find automatically. Classes you deploy in the WEB- INF/classes and JAR files in WEB-INF/lib are available to the container and you don’t have to say anything

6 M AKING STATIC CONTENT AND JSP S DIRECTLY ACCESSIBLE When you deploy static HTML and JSPs, you can choose whether to make them directly accessible from outside the web app. By directly accessible, we mean that a client can enter the path to the resource into his browser, and the server will return the resource. – You can prevent direct access by putting files under WEB-INF

7 U SE ANT TO BUILD THE WAR FILE You can use Ant task war to build a WAR file Two options: Use ANT war task Use ANT jar task

8 (only part of the build file is shown here) <javac srcdir="src" destdir="classes">

9 WAR FILE

10 U SE A NT TO BUILD WAR FILE If you have third party library JAR files, when deployed, it is located at WEB-INF/lib direcotry of your web application. If you build a WAR file, you may include these libraries in corresponding place

11 You may create a dir lib to store other third party library such as JDBC driver Pack the third party library here

12 WAR FILE We can use ANT jar task to build the WAR file too. In this case, you create another dir called build as the place for assembling all the files in this place. Using ANT war task is more convenient, since this assembly step is avoided.

13 …………………. Directory build and its sub- directories are places for assembling files

14 Since WAR file is simply a JAR file, we can use ANT jar task to jar the files we assembled in the build directory.

15 H OW TO FIND OUT WHAT IS INSIDE THE GENERATED WAR FILE C:\J2EE_C~1\LAB9_A~2\LAB9_A~1\dist> jar tvf lab9a_2.war 0 Tue Nov 23 13:53:28 EST 2010 META-INF/ 106 Tue Nov 23 13:53:26 EST 2010 META-INF/MANIFEST.MF 0 Tue Nov 23 13:53:28 EST 2010 WEB-INF/ 0 Tue Nov 23 13:53:28 EST 2010 WEB-INF/classes/ 0 Tue Nov 23 13:53:28 EST 2010 WEB-INF/classes/edu/ 0 Tue Nov 23 13:53:28 EST 2010 WEB-INF/classes/edu/nku/ 0 Tue Nov 23 13:53:28 EST 2010 WEB- INF/classes/edu/nku/j2ee/ 0 Tue Nov 23 13:53:28 EST 2010 WEB-INF/lib/ 235 Tue Nov 23 13:53:28 EST 2010 WEB- INF/classes/edu/nku/j2ee/CounterBean.class 304 Tue Nov 23 13:53:28 EST 2010 WEB-INF/web.xml 481 Tue Nov 23 13:53:28 EST 2010 counter.jsp 488 Tue Nov 23 13:53:28 EST 2010 index.htm 2573 Tue Nov 23 13:53:28 EST 2010 index.jpg 616 Tue Nov 23 13:53:28 EST 2010 prog.jsp If you want to find out what is inside the generated WAR file, you can use the command: jar tvf name_of_WAR_file You may noticed that when you use ant war task or jar task to generate the WAR file, it automatically creates a directory called META-INF and a file MANIFEST.MF under it.

16 D EPLOY WAR FILE This simply drop the file under webapps dir of tomcat.


Download ppt "C HAPTER 11 D EPLOYING YOUR WEB APP. WAR FILE A WAR file is simply a snapshot of your web app structure, in a nice portable, compressed form (it is really."

Similar presentations


Ads by Google