[SpringBoot][WebMVC] 웹 JAR

2022. 11. 10. 12:05JAVA/Spring

1. 웹 JAR란 무엇인가?

  • Web JAR는 클라이언트에서 사용하는 웹 라이브러리(jquery와 bootstrap)을 JAR 파일 안에 패키징한것이다.

 

2. 실습, Jquery 웹 라이브러리를 의존성 추가

1. jquery 의존성 추가

implementation 'org.webjars.bower:jquery:3.6.1'

 

2. html 파일에 jquery 소스 주소를 정의하고 jquery 쿼리 함수 호출

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="webjars/jquery/3.6.1/dist/jquery.min.js"></script>
    <title>Title</title>
</head>
<body>
    <h1>hello world modified</h1>

    <script>
        $(function(){
            alert("ready!!");
        });
    </script>
</body>
</html>

 

3. 실습, WebJars Locator Core 의존성 추가

jquery같은 웹 라이브러리의 버전을 생략하기 위해서는 WebJars Locator Core 의존성 라이브러리를 추가해야 합니다.

 

1. WebJars Locator Core 의존성 추가

implementation 'org.webjars:webjars-locator-core:0.52'

 

2. jquery 소스 주소 정의를 다음과 같이 수정후 실행하여 결과를 확인합니다.

<script src="webjars/jquery/dist/jquery.min.js"></script>

 

References

[인프런] 스프링 부트 개념과 활용