12war.docx

4
How to create WAR file in eclipse? What is war file? WAR stands for Web application Archive. WAR is a compressed file format like the ZIP file which i servlet jar and static web resources etc in a specific hierarchical director! structure called W file but follow a specific hierarchical director! structure. WAR files are deplo!ed to the applic 'omcat or (ava "" server like (#oss etc. Note: WAR files have the .war extension and contains the whole web application. How to create WAR file in eclipse? )et us discuss it with an e*ample. We are creatin+ a java project which contain one class Armstro 'he Armstron+%umber.java contains one static method armstron+,int num- which returns true if the armstron+ number otherwise returns false. We will create the (AR file of this and use (AR file in Step 1: Right click on the proect and click on !xport. Step ": Select the WAR file and click on Next.

Transcript of 12war.docx

How to create WAR file in eclipse?What is war file?WAR stands for Web application Archive. WAR is a compressed file format like the ZIP file which includes jsp, servlet, jar and static web resources etc in a specific hierarchical directory structure called WEB-INF. It is like jar file but follow a specific hierarchical directory structure. WAR files are deployed to the application server like Tomcat or Java EE server like JBoss etc.Note: WAR files have the .war extension and contains the whole web application.How to create WAR file in eclipse?Let us discuss it with an example. We are creating a java project which contain one class ArmstrongNumber.java. The ArmstrongNumber.java contains one static method armstrong(int num) which returns true if the num is an armstrong number otherwise returns false. We will create the JAR file of this and use JAR file in other project.Step 1: Right click on the project and click on Export.

Step 2: Select the WAR file and click on Next.

Step 3: Enter the destination and click on Finish.

How to create war file using ant?What is war file?WAR stands for Web application Archive. WAR is a compressed file format like the ZIP file which includes jsp, servlet, jar and static web resources etc in a specific hierarchical directory structure called WEB-INF. It is like jar file but follow a specific hierarchical directory structure. WAR files are deployed to the application server like Tomcat or Java EE server like JBoss etc.Note: WAR files have the .war extension and contains the whole web application.How to create war file using ant?As we discussed all basic concepts of Apache ant, let us see the below example to create war file using ant.In build.xml file:1. src.dir:It specify the project source folder.2. classes.dir:It specify the classes compilation output folder.3. lib.dir:It specify the output folder for the jar files.4. dist.dir:It specify the output folder for the created war.Example explanation:When we run the build.xml file, control first go on the project element and look for the default target. In our example mainTarget is the default target so control go on the mainTarget. Then control looks for those targets on which mainTarget depends. The mainTarget depends on compile and war target. The war target depends on compile target which is further depends upon clean and makedir target. So first clean target will execute followed by makedir, compile, war and mainTarget. The war task in the war target is responsible for creating the war file.Example:index.jsp Ant Create War Example This is an Ant Create War Example.

build.xml

Main target

Console:Buildfile: D:\TestWorkspace\AntCreateWar\build.xmlclean: [delete] Deleting directory D:\TestWorkspace\AntCreateWar\WebRoot\WEB-INF\classes [delete] Deleting directory D:\TestWorkspace\AntCreateWar\WebRoot\WEB-INF\lib [delete] Deleting directory D:\TestWorkspace\AntCreateWar\distmakedir: [mkdir] Created dir: D:\TestWorkspace\AntCreateWar\WebRoot\WEB-INF\classes [mkdir] Created dir: D:\TestWorkspace\AntCreateWar\WebRoot\WEB-INF\lib [mkdir] Created dir: D:\TestWorkspace\AntCreateWar\distcompile: [javac] D:\TestWorkspace\AntCreateWar\build.xml:26: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable buildswar: [war] Building war: D:\TestWorkspace\AntCreateWar\dist\armstrong.ant.teat.warmainTarget:BUILD SUCCESSFULTotal time: 350 milliseconds

Download this example.