programming language/Java

Jar 과 War의 차이점은?

공대키메라 2022. 1. 16. 23:35

필자는 Inflearn을 강의를 굉장히 자주 듣는다.

 

최근 Spring 기본 강의를 듣고있는 중에 Spring initializr에서 어떤 프로젝트는 Jar로, 다른것은 War로 다운을 받는데 

 

이 두개의 차이점을 잘 모르겠다!

 

그래서 이 글을 통해 공부할 것이다. 

 

우선 google에 간단하게 

 

Jar(Java ARchive) vs War(Web application ARchive)

 

를 검색해보니 맨 상단에 stack overflow가 있다. 

 

1) https://stackoverflow.com/questions/5871053/difference-between-jar-and-war-in-java

 

들어가서 보니 이런 말이 있다. 

 

From Java Tips: Difference between ear jar and war files:

These files are simply zipped files using the java jar tool. These files are created for different purposes. Here is the description of these files:

  • .jar files: The .jar files contain libraries, resources and accessories files like property files.
  • .war files: The war file contains the web application that can be deployed on any servlet/jsp container. The .war file contains jsp, html, javascript and other files necessary for the development of web applications.

 

이 답변도 알고보니 Java Tips라는 사이트에서 참조한건데 읽어보니 다음과 같다. 

 

이 파일들 (Jar,랑 War) 는 간단히 자바 jar 툴을 사용하는 압축된 파일들 입니다. 이것들은 다른 목적으로 만들어 졌습니다. 이 파일의 설명이 여기 있습니다.

  .jar files: .jar 파일들은 라이브러리, 리소스, 프로퍼티 파일 같은 악세서리 파일을 포함합니다.
  .war files
         : war 파일들은 아무 servlet/jsp 콘테이너에 배치될 수 있는 웹 애플리케이션을 포함합니다. 
         : war 파일들은 jsp, html, javascript 그리고 웹 애플리케이션 개발에 필요한 다른 필요한 파일들을 포함합니다. 

 

읽어보니 war가 뭘 더 가진것 같은데 이 설명만으로는 성이 안찬다. 

 

다른 글도 찾아보았다. 

 

출처 : https://programmer93.tistory.com/40 

 

이것도 좀 모자른데...

 

그러다가 baeldung사이트에서 하나를 찾았다. 

 

출처 : https://www.baeldung.com/java-jar-war-packaging

 

4. Key Differences

So, what are the key differences between these two archive type

The first and most obvious difference is the file extension. JARs have the .jar extension, whereas the WAR file has the .war extension.

The second main difference is their purpose and the way they function. JAR files allow us to package multiple files in order to use it as a library, plugin, or any kind of application. On the other hand, WAR files are used only for web applications.

The structure of the archives is also different. We can create a JAR with any desired structure. In contrast, WAR has a predefined structure with WEB-INF and META-INF directories.

Finally, we can run a JAR from the command line if we build it as an executable JAR without using additional software. Or, we can use it as a library. In contrast, we need a server to execute a WAR.

 

주요 차이점

그래서, 두개의 archive 타입 사이에 차이점이 뭘까?

첫번째이자 가장 명확한 차이점은 파일 확장이다. JARs는 .jar 확장을 가진 반면 WAR 파일은 .war 확장을 가진다. 

두번째 주요 차이점은 그들의 목적과 작동하는 방식이다. JAR 파일들은 우리가 라이브러리, 플러그인, 또는 아무 종류의 어플리케이션으로 사용할 수 있도록 다수의 파일들을 pakage하도록 한다. 

반면, war 파일들은 웹 애플리케이션에서만 사용된다. 
archives의 구조 또한 다르다. 우리가 원하는대로 jar를 만들수 있다. 대조적으로, war는 web-inf와 meta-inf 디렉토리로 미리 정의된 구조를 가진다. 

마지막으로, 우리가 추가적인 소프트웨어 없이 실행가능한 jar 로 생성한다면, 커맨드 라인으로 jar를 실행할 수 있다. 
또한, 우리는 라이브러리 처럼 사용할 수 있습니다. 대조적으로, 우리는 war를 실행하기 위해 서버가 필요합니다. 

 

위의 내용으로 추합하면...

 

같은 파일인데 목적이 다르고, 확장성에 차이점이 있고 jar는 server없이 구동 가능하지만, war는 server가 필요하다. 

 

그런거같은데...

 

'programming language > Java' 카테고리의 다른 글

제네릭 이해하기  (2) 2022.03.26
interface vs abtract class  (4) 2022.02.06
BigInteger 사용하기  (0) 2022.01.18
HashTable, HashMap, ConcurrentHashmap  (2) 2022.01.10
DTO? VO? 개념 정리 및 사용 이유  (3) 2021.08.29