1. Jar와 war의 차이점
Jar SpringBoot의 내장톰켓 vs. War 외장톰켓, jsp 이용시
Maven 혹은 Gradle을 통해 내려받는 라이브러리들(External Libraries)은 CLASS 파일들이 묶인 jar파일로 구성되어 있는 것을 확인할 수 있다.
그리고 서비스 배포시에는 프로젝트를 WAR 포맷으로 묶어서 /webapps 등의 지정된 경로에 넣고 Tomcat 등의 웹 컨테이너(Web Container)를 이용하여 deploy하는 식으로 서비스를 많이 올리곤 한다.
Jar 과 war
https://ifuwanna.tistory.com/224
* 스프링부트에서의 Jar와 War
스프링부트 프로젝트를 새로 생성할 때, Jar(Java Archive) 또는 War(Web Application Archive) 로 패키징 방식을 선택할 수 있다.
Jar는 class 및 설정 파일들을 압축해서 만들어진 하나의 어플리케이션 혹은 라이브러리다.
War는 JSP나 Servlet 등 WAS 컨테이너 위에서 동작하게끔 빌드된 형태이다. 웹 어플리케이션을 어떻게 설정할 지에 대한 정의가 있는 web.xml 파일을 포함(반드시는 아님 Web Application Initailizer로 대체 가능하다.)
JAR파일에는 WAS가 내장되어 있다.( embedded tomcat을 jar에 내장해서, jar파일로도 빌드가 가능하다.)
따라서 기존 톰켓과 같은 컨테이너를 이용해야 했던 스프링보다 훨씬 간단하게 어플리케이션을 제작/배포할 수 있는 것입니다. 하지만 필요에 따라 외부 WAS를 이용해야할 경우도 생기는데, 이때는 WAR 파일로 패키징을 해야한다.
※ SpringBoot에서 War 로 배포하는 법 : https://prde.tistory.com/330
(출처 : https://mongsil1025.github.io/til/server/warjar/)
https://programmer93.tistory.com/40
https://hye0-log.tistory.com/27
2. 스프링부트에서의 Jar와 Plain Jar 파일 차이
1. batch-app-0.0.1-SNAPSHOT.jar:
This is likely the Spring Boot executable JAR that is created when you package your Spring Boot application. It typically contains:
• The compiled classes of your application.
• All the dependencies required to run the application.
• A manifest with a Main-Class attribute that allows the JAR to be directly executed with the java -jar command, making it a fat JAR (a JAR that includes all dependencies bundled).
This JAR is ready to be run as a self-contained application.
2. batch-app-0.0.1-SNAPSHOT-plain.jar:
This is likely a plain JAR file. A plain JAR:
• Contains only the compiled classes of your application, without dependencies.
• It is not executable, meaning it cannot be run directly using java -jar.
• Typically, this type of JAR is used when the dependencies are managed separately, like in a traditional Java environment where dependencies are provided by an application server or a custom classpath.
Key Differences:
• Executable JAR (batch-app-0.0.1-SNAPSHOT.jar): Contains everything (code + dependencies), can be run directly (java -jar).
• Plain JAR (batch-app-0.0.1-SNAPSHOT-plain.jar): Contains only your code, needs additional dependencies, and cannot be run directly.
jar, plain jar 파일 빌드시 파일 이름 변경 방법
jar {
archiveBaseName.set("my-custom-plain-jar-name")
}
bootJar {
archiveBaseName.set("my-custom-executable-jar-name")
}
Purpose of a Plain JAR File
1. Lightweight Packaging: Plain JAR files only contain your application’s classes without bundling external dependencies. This can be useful when you don’t want to include large dependencies in the JAR (e.g., when dependencies are already managed elsewhere, like in an application server).
2. Separation of Concerns: In enterprise environments, plain JARs are used when the infrastructure is already set up to manage and provide the dependencies. This is typical in environments like:
• Application Servers: These servers (e.g., Tomcat, JBoss, WebSphere) often manage dependencies and classpaths, so you only need to deploy the application JAR without its dependencies.
• Shared Libraries: If your project depends on common libraries that are shared across multiple applications, using a plain JAR ensures you don’t duplicate dependencies.
3. For Libraries or APIs: When you’re building a reusable library or API for other projects to consume, you usually create a plain JAR. Consumers of your library are expected to manage dependencies on their own.
4. Testing and Smaller Modules: Sometimes plain JARs are generated for smaller, non-executable modules in a larger system where each module is responsible for different functionality. You might not need an executable JAR for each part.
In short, plain JARs are useful when you have a structured environment that already handles classpath management and dependencies, or when you’re building reusable components or libraries.
3. Jar, palin Jar, War 차이
A plain JAR file and a WAR file (Web Application Archive) serve different purposes, even though both are forms of archives for Java applications. Here are the key differences and similarities between them:
1. Purpose:
• Plain JAR File:
• A JAR (Java ARchive) is typically used for standalone applications or libraries.
• It can contain Java class files, resources (like images or properties files), and manifest files.
• Plain JAR files specifically do not bundle dependencies or configuration to run the application directly (like a Spring Boot “fat JAR” does).
• WAR File:
• A WAR (Web Application Archive) is used for web applications.
• It is designed to be deployed in a Servlet container like Tomcat, Jetty, JBoss, etc.
• A WAR contains web-related resources like WEB-INF/, JSPs, servlets, HTML files, JavaScript, etc., along with the application’s classes and libraries.
2. Structure:
• Plain JAR File:
• Typically contains just your application’s .class files and resources.
• It may have a manifest file but doesn’t contain any web-specific configurations like web.xml.
• It does not bundle external dependencies unless it’s a “fat” or executable JAR.
• WAR File:
• Has a defined structure for web applications, including:
• WEB-INF/ directory for deployment descriptors (like web.xml), classes, and libraries (WEB-INF/lib).
• Static resources like HTML, JSP, CSS, JavaScript files in the root directory.
• Typically includes dependencies within WEB-INF/lib.
3. Deployment:
• Plain JAR File:
• Plain JAR files are not web-deployable. You run them using the java -cp command or by adding them to another application’s classpath.
• You cannot deploy a plain JAR directly into a servlet container (like Tomcat), unless you wrap it in a WAR or an executable JAR.
• WAR File:
• WAR files are specifically designed for web deployments and can be deployed in a servlet container or an application server.
• The servlet container manages the lifecycle and classloading of the WAR.
4. Main Class and Execution:
• Plain JAR File:
• Usually requires a Main-Class entry in its manifest if you want to run it as an application (via java -jar or java -cp).
• But it cannot be run directly as a web application.
• WAR File:
• Contains no Main-Class and isn’t run directly.
• Instead, it relies on the servlet container to load and execute the web application.
5. Use Cases:
• Plain JAR File:
• Used for standalone desktop or console applications.
• Can be a library used by other Java applications.
• WAR File:
• Used for web applications with dynamic web pages (servlets, JSPs, etc.).
• Deployable to servlet containers like Tomcat or Jetty.
4. JVM, JDK, JRE의 차이점
https://ko.strephonsays.com/what-is-the-difference-between-jdk-and-jre
# 컴파일러가 컴파일하고 JVM이 읽어서 OS에게 명령~
1) Java 컴파일러 : java 프로그램을 바이트코드라는 중간 코드로 변환 ->
2) JVM : Java Virtual Machine 으로 바이트 코드를 기계어 코드로 변환하는 추상 기계
( JVM은 플랫폼에 의존적이다. 즉 리눅스의 JVM과 윈도우의 JVM은 다르다. 단, 컴파일된 바이너리 코드는 어떤 JVM에서 도 동작시킬 수 있다. )
3) 소스코드는 CPU가 이해할 수 없고, 프로그래머만 이해 가능 ( Java Compiler가 소스코드 -> 바이트코드로 변환
JVM이 바이트 코드 기계어 코드로 변환 따라서 CPU가 프로그램의 주어진 명령에 따라 작업 실행
4) JRE : 자바 런타임 환경으로 JVM, Java 클래스 라이브러리 및 Java 응용 프로그램을 실행하는데 필요한 기타 파일의 조합이다. 따라서 JRE를 설치하면 Java 프로그램만 실행할 수 있다.(프로그램 개발은 불가능)
5) JDK : 자바 개발 킷트 : JRE + 기타 개발도구(컴파일러(javac), 아카이버(jar), 문서생성기(javadoc))로 구성됨.
https://m.blog.naver.com/duqrlwjddns1/221770110714
'Back-end > Java Language' 카테고리의 다른 글
static 클래스 vs instance 클래스, static 변수, 메소드, final (0) | 2024.05.08 |
---|---|
Java Wrapper class (0) | 2023.01.29 |
Java Optional, Stream (0) | 2023.01.29 |
@JsonIgonore, @JsonProperty, @JsonNaming & Jackson Object Mapper (0) | 2023.01.07 |
Exception Handling (0) | 2023.01.01 |