About jar and war file


General J2EE: About jar and war file

  1. About jar and war file (3 messages)

    Hi !
    This is my understanding,
    A jar file is a java archive file, which bundles java classes(utility) with some static files like images or videos for easy accessibility.

    A war file is a web application archive which bundles JSP/Servlet classes, html, images and videos.

    My question is, can jar have only java classes and not JSP files or html files. But war file can also have jsp files and html files, is that the prime difference between jar and war files.


    Threaded Messages (3)

  2. About jar and war file[ Go to top ]


    The main difference between a JAR and a WAR is that a JAR is not really a single purpose format, while a WAR is. With a JAR file, you can package lots of different things. Usually you package up Java classes, but you could put pretty much anything into a JAR file, and you can create JARs that have whatever files and directory formats you want. For instance, Oracle (at least in 8.1.x) actually uses JAR files to distribute the Oracle software on the install CDs, and IBM uses them to distribute an installable version of the documentation for WebSphere. Technically you can put JSP pages, HTML pages, servlet classes, etc. in a JAR, but you generally don't -- you use a WAR.

    WAR files are JAR files with a specific format. This format is defined in the servlet spec (which you can look at on the java.sun.com site). Essentially, the WAR file is a standard format for web applications that has specific directories and specific files. This includes a WEB-INF directory, a WEB-INF/web.xml file used to describe the application, a WEB-INF/lib directory for JAR files used by the application, and a WEB-INF/classes directory for class files that aren't distributed in a JAR. You would put the pages (JSPs and HTML) in the WAR as well. Then, you can distribute your application as one file, instead of as a collection of images, HTML pages, and Java classes.

    Hope this helps!

  3. About jar and war file[ Go to top ]

    Is there any benefit, other than having everything in a single file, to using war/jar files for application deployment?
  4. About jar and war file[ Go to top ]

    The major benefit is having everything in a single file. It's just easier to distribute a jar or war file than it is to distribute an entire directory tree. This is especially true with web applications, since you have classes, html pages, xml files, etc. to worry about, not just Java classes.

    With some application servers, you have to use jar or war files, so you wouldn't have a choice. EJBs are generally distributed in a jar file, and tag libraries often are as well. Even when it's not a requirement, it's often very convenient. App servers like WebSphere, Weblogic, JRun, etc can take a war file and directly deploy it without requiring much beyond the name of the war file to deploy.