Jar War Zip

zip -> jar -> war

JAR

  • Definication
    JAR are built on the ZIP format and typically have a .jar file extension.(come from zip)
    A JAR (Java Archive) is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file for distribution.
    JAR files are archive files with which include a Java-specific manifest file.

  • Extraction
    The contents of a JAR file may be extracted using any standard decompression software(zip command etc.), or the jar command line utility: “jar -xf foo.jar”.

1
2
unzip foo.jar
jar -xf foo.jar
  • Executable JAR files
    An executable Java program can be packaged in a JAR file, along with any libraries the program uses.
    Executable JAR files have the manifest specifying the entry point class with Main-Class: myPrograms.MyClass and an explicit Class-Path (and the -cp argument is ignored). Some operating systems can run these directly when clicked. The typical invocation is java -jar foo.jar from a command line.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#./META_INF/MANIFEST.MF
Manifest-Version: 1.0
Implementation-Title: project_title
Implementation-Version: 0.0.1-SNAPSHOT
Archiver-Version: Plexus Archiver
Built-By: build_user_name
Implementation-Vendor-Id: com.example
Spring-Boot-Version: 1.5.1.RELEASE
Implementation-Vendor: Pivotal Software, Inc.
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.app.Application
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_111
Implementation-URL: http://projects.spring.io/spring-boot/imaid/

Execute Jar file

1
java -Xms1024m -Xmx1024m -XX:ReservedCodeCacheSize=128m -XX:MaxMetaspaceSize=256m -jar /path/to/jarfile.jar

WAR

  • Definication
    In software engineering, a WAR file (or Web application ARchive) is a JAR file used to distribute a collection of JavaServer Pages, Java Servlets, Java classes, XML files, tag libraries, static web pages (HTML and related files) and other resources that together constitute a web application. (come from jar file)

  • Extraction
    Same with jar file.

1
2
unzip foo.war
jar -xf foo.war
  • Executable WAR files
    use Tomcat

Genarate jar/war/zip to deploy

Maven project can generate jar/war simply by setting pom.xml

1
2
3
<packaging>jar</packaging>
or
<packaging>war</packaging>

Genarate

1
mvn package

Play framework use dist command generate zip file, or use sbt-assembly plugin to generate jar file.

1
sbt dist