본문 바로가기
Programming/JAVA

[Spring boot] 4. 빌드해보기 (윈도우에서)

by Berasix 2022. 12. 21.
반응형

1. jar 파일 만들기

.jar 파일을 만들려고 했는데, 아래와 같은 문구가 떴다.

PS C:\Users\berasix\IdeaProjects\demo> .\gradlew build

ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

 

시스템 환경변수에 JAVA_HOME 이 등록 안되어 있어 그렇다.

C:\Users\berasix\.jdks\corretto-18.0.2  를 등록해 줬다. (bin 디렉토리가 포함되어 있으면 안된다)

[ 다시 말하면, C:\Users\계정\.jdks\버전 ]

또한 java 명령 사용을 하기 위해 Path 에 C:\Users\berasix\.jdks\corretto-18.0.2\bin 의 경로도 추가해 주도록 한다.

 

Intellij 를 재구동 하고 build를 하면 아래와 같이 성공이다.

PS C:\Users\berasix\IdeaProjects\demo> .\gradlew build

Welcome to Gradle 7.5.1!

Here are the highlights of this release:
 - Support for Java 18
 - Support for building with Groovy 4
 - Much more responsive continuous builds
 - Improved diagnostics for dependency resolution

For more details see https://docs.gradle.org/7.5.1/release-notes.html

Starting a Gradle Daemon, 1 incompatible and 2 stopped Daemons could not be reused, use --status for details

BUILD SUCCESSFUL in 11s
7 actionable tasks: 6 executed, 1 up-to-date
PS C:\Users\kshrd\IdeaProjects\demo>

 

2. jar 파일 확인하기

build/libs/demo-0.0.1-SNAPSHOT.jar 파일이 생성되어 있다.

 

3. 생성된 jar 실행해 보기

PS C:\Users\berasix\IdeaProjects\demo> cd .\build\
PS C:\Users\berasix\IdeaProjects\demo\build> cd .\libs\
PS C:\Users\berasix\IdeaProjects\demo\build\libs> java -jar .\demo-0.0.1-SNAPSHOT.jar

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.0.0)

2022-12-21T15:08:13.590+09:00  INFO 11056 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication using Java 18.0.2 with PID 11056 (C:\Users\kshrd\IdeaProjects\demo\build\libs\demo-0.0.1-SNAPSHOT.jar started by baby in C:\Users\kshrd\IdeaProjects\demo\build\libs)
2022-12-21T15:08:13.592+09:00  INFO 11056 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to 1 default profile: "default"
2022-12-21T15:08:14.207+09:00  INFO 11056 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-12-21T15:08:14.213+09:00  INFO 11056 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-12-21T15:08:14.214+09:00  INFO 11056 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.1]
2022-12-21T15:08:14.277+09:00  INFO 11056 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-12-21T15:08:14.278+09:00  INFO 11056 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 645 ms
2022-12-21T15:08:14.409+09:00  INFO 11056 --- [           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page: class path resource [static/index.html]
2022-12-21T15:08:14.524+09:00  INFO 11056 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2022-12-21T15:08:14.537+09:00  INFO 11056 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 1.202 seconds (process running for 1.463)

 

4. 실행 확인

 

5. 참고하기

혹시 문제가 있는 경우 clean 명령을 사용하면 build 폴더가 사라진 후에 다시 build 된다.

> .\gradlew clean build

 

 

이 글은 필자가 분석, 공부하면서 작성한 포스트입니다. 

잘못된 부분에 대해 알려주시면 수정하도록 하겠습니다.

728x90

댓글