1. 설명

Fat JAR란 모든 의존성에 있는 라이브러리가 자체 포함되어 있는 JAR 파일을 뜻한다. Fat JAR는 java -jar 명령어로 단독 실행할 수 있다.

자바 패키징 방식에 따른 이름은 다음과 같다.

  • Skinny – Contains ONLY the bits you literally type into your code editor, and NOTHING else.
  • Thin – Contains all of the above PLUS the app’s direct dependencies of your app (db drivers, utility libraries, etc).
  • Hollow – The inverse of Thin – Contains only the bits needed to run your app but does NOT contain the app itself. Basically a pre-packaged “app server” to which you can later deploy your app, in the same style as traditional Java EE app servers, but with important differences.
  • Fat/Uber – Contains the bit you literally write yourself PLUS the direct dependencies of your app PLUS the bits needed to run your app “on its own”.

2. 생성방법

Fat JAR 생성이 가능하도록 플러그인을 추가한 후,

2.1. Maven

<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
  </plugins>
</build>

$ mvn package

(packge goal)

2.2. Gradle

$ gradle assmble

(bootRun goal)