Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Archives
Today
Total
관리 메뉴

한바다

스프링부트 자바 jar로 배포하기 본문

카테고리 없음

스프링부트 자바 jar로 배포하기

한바다진화 2024. 8. 28. 15:12

❇ 스프링부트 자바 jar로 배포하기

이클립스 전산을 열어 스프링부트를 실행시킨 후(백앤드 실행) 프론트앤드 (리액트)를 실행하여

localhost로 접속하였는데 스프링부트자바를 jar로 배포시 이클립스 전산을 키지 않고

cmd창에서 실행 시킬 수 있다.

 

✓ 우선 위와 같은 작업을 진행하기 위해 첫번째로 해당폴더 경로 build.gradle이 있는 위치에서 cmd 창을 열어준다

✓ 백엔드 자바 배포

cmd 창에 gradle build 입력후 엔터를 친다!

C:\Users\user1\Spring-React-Workspace\JPA_chicken>gradlew build

[ gradlew build 입력시 나온 에러내용]

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

FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'JPA_chicken'.
A problem occurred configuring root project 'JPA_chicken'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.3.2.
     Required by:
         project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.3.2
      > Dependency requires at least JVM runtime version 17. This build uses a Java 11 JVM.
      
      * Try:
> Run this build using a Java 17 or newer JVM.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 5s

 

[에러 내용과 해결 방안]

위 에러는 자바가 11버전이여서 나타난 오류로 java17버전으로 재설치후 환경설정을 진행해줘야 한다.

- 자바17버전 다운받기!

https://www.oracle.com/kr/java/technologies/downloads/#jdk17-windows

 

Download the Latest Java LTS Free

Subscribe to Java SE and get the most comprehensive Java support available, with 24/7 global access to the experts.

www.oracle.com

: 자바17버전을 다운로드 설치 후 시스템속성에서 환경변수를 수정해주었다.

검색창> 환경변수 입력>

위 환경변수 편집에서 노란색표기된 부분이 수정되었다

▶ 1~3번 경로로 들어가 환경변수 편집에서 숫자 11을 17로 변경후 확인/확인/확인을 눌러주었다!

 

✓ 이제 자바버전을 17버전으로 맞춰으니 아래의 경로로 자바버전을 확인해준다

 

이제 다시 백엔드 자바 배포를 진행하로 간다.

C:\Users\user1\Spring-React-Workspace\JPA_chicken>gradlew build
Starting a Gradle Daemon, 5 incompatible and 1 stopped Daemons could not be reused, use --status for details
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
2024-08-28T11:25:29.994+09:00  INFO 6788 --- [JPA_chicken] [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2024-08-28T11:25:29.996+09:00  INFO 6788 --- [JPA_chicken] [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2024-08-28T11:25:30.001+09:00  INFO 6788 --- [JPA_chicken] [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.

BUILD SUCCESSFUL in 17s
7 actionable tasks: 7 executed

 

위와 같이 BUILD SUCCESSFUL이 뜨면 jar 파일로 만들어졌다!

 

✓ 이제 폴더 경로에 build폴더 생성되었는지 확인한다

build폴더에서 libs폴더로 들어가면 jar파일을 확인할수 있다. 해당폴더 경로에서 cmd창을 입력한다.

C:\Users\user1\Spring-React-Workspace\JPA_chicken\build\libs>java -jar JPA_chicken-0.0.1-SNAPSHOT.jar

▶ 명령어 java -jar 뛰고 탭키를 눌러주어 해당명령어를 완성한 후 enter를 친다

C:\Users\user1\Spring-React-Workspace\JPA_chicken\build\libs>java -jar JPA_chicken-0.0.1-SNAPSHOT.jar

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.3.2)

2024-08-28T11:28:12.397+09:00  INFO 4480 --- [JPA_chicken] [           main] com.kh.JpaChickenApplication             : Starting JpaChickenApplication v0.0.1-SNAPSHOT using Java 17.0.12 with PID 4480 (C:\Users\user1\Spring-React-Workspace\JPA_chicken\build\libs\JPA_chicken-0.0.1-SNAPSHOT.jar started by user1 in C:\Users\user1\Spring-React-Workspace\JPA_chicken\build\libs)
2024-08-28T11:28:12.400+09:00  INFO 4480 --- [JPA_chicken] [           main] com.kh.JpaChickenApplication             : No active profile set, falling back to 1 default profile: "default"
2024-08-28T11:28:12.907+09:00  INFO 4480 --- [JPA_chicken] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2024-08-28T11:28:12.952+09:00  INFO 4480 --- [JPA_chicken] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 38 ms. Found 1 JPA repository interface.
2024-08-28T11:28:13.013+09:00  WARN 4480 --- [JPA_chicken] [           main] o.m.s.mapper.ClassPathMapperScanner      : No MyBatis mapper was found in '[com.kh]' package. Please check your configuration.
2024-08-28T11:28:13.356+09:00  INFO 4480 --- [JPA_chicken] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 9090 (http)
2024-08-28T11:28:13.366+09:00  INFO 4480 --- [JPA_chicken] [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2024-08-28T11:28:13.367+09:00  INFO 4480 --- [JPA_chicken] [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.26]
2024-08-28T11:28:13.401+09:00  INFO 4480 --- [JPA_chicken] [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2024-08-28T11:28:13.402+09:00  INFO 4480 --- [JPA_chicken] [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 954 ms
2024-08-28T11:28:13.534+09:00  INFO 4480 --- [JPA_chicken] [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2024-08-28T11:28:13.577+09:00  INFO 4480 --- [JPA_chicken] [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 6.5.2.Final
2024-08-28T11:28:13.605+09:00  INFO 4480 --- [JPA_chicken] [           main] o.h.c.internal.RegionFactoryInitiator    : HHH000026: Second-level cache disabled
2024-08-28T11:28:13.832+09:00  INFO 4480 --- [JPA_chicken] [           main] o.s.o.j.p.SpringPersistenceUnitInfo      : No LoadTimeWeaver setup: ignoring JPA class transformer
2024-08-28T11:28:13.856+09:00  INFO 4480 --- [JPA_chicken] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2024-08-28T11:28:14.066+09:00  INFO 4480 --- [JPA_chicken] [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@18989e0
2024-08-28T11:28:14.067+09:00  INFO 4480 --- [JPA_chicken] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2024-08-28T11:28:14.635+09:00  INFO 4480 --- [JPA_chicken] [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)
2024-08-28T11:28:14.667+09:00  INFO 4480 --- [JPA_chicken] [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2024-08-28T11:28:14.884+09:00  WARN 4480 --- [JPA_chicken] [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2024-08-28T11:28:15.081+09:00  WARN 4480 --- [JPA_chicken] [           main] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates, check your Thymeleaf configuration, or set spring.thymeleaf.check-template-location=false)
2024-08-28T11:28:15.209+09:00  INFO 4480 --- [JPA_chicken] [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port 9090 (http) with context path '/'
2024-08-28T11:28:15.223+09:00  INFO 4480 --- [JPA_chicken] [           main] com.kh.JpaChickenApplication             : Started JpaChickenApplication in 3.102 seconds (process running for 3.429)
2024-08-28T11:28:55.217+09:00  INFO 4480 --- [JPA_chicken] [nio-9090-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'

 

[cmd창에 스프링부트 에러]

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-08-28T11:40:41.025+09:00 ERROR 18728 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   :

***************************
APPLICATION FAILED TO START
***************************

Description:

Web server failed to start. Port 9090 was already in use.

Action:

Identify and stop the process that's listening on port 9090 or configure this application to listen on another port.


C:\Users\user1\Spring-React-Workspace\JPA_pizza\build\libs>
->위 에러를 해결해줘

 

[에러발생원인과 해결]

해당 에러는 이미 다른프로그램이 9090번 포트를 사용하고 있어서 발생한 문제로 해당 포트를 꺼주면 된다!

난 이전 프로젝트 9090포트가 실행중이여서 발생한 문제거 해당포트를 끄고 재 실행시 정상적으로 작동하였다!

또는 애플리케이션이 다른 포트를 사용하도록 설정하는 방법이 있다.