1. 첫번째 SpringBootServletInitializer 확인
- SpringBootServletInitializer 상속받는 것으로 변경
- Embed servlet 을 'provided' 로 변경
- war로 빌드
WAR 로 스프링 부트를 시작하지 않아서 다음 코드가 없을 경우
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; public class ServletInitializer extends SpringBootServletInitializer { protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(new Class[] { CowayhksApplication.class }); } }
아래 코드를 추가
달라진 것은 SpringBootServletInitializer 를 상속받고, configure 함수를 override 한다.
@SpringBootApplication public class SpringBootSampleApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(SpringBootSampleApplication .class, args); } protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(SpringBootSampleApplication .class); } }
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
war로 빌드
그리고 아래 처럼 packaging 태그를 war로 수정
<packaging>war</packaging>
참조: https://4urdev.tistory.com/84 [Simplify]
2. war패키징 pom.xml 설정, war file 만들기, web.xml 자동생성
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>kr.co.itcen</groupId> <artifactId>helloweb</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <!-- 라이브러리 항목 --> <dependencies> </dependencies> <build> <sourceDirectory>src/main/java</sourceDirectory> <resources> <resource> <directory>${project.basedir}/src/main/resources</directory> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <!-- 컴파일러가 사용하는 플러그인 --> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <source>1.8</source> <!-- version --> <target>1.8</target> </configuration> </plugin> <!-- war plugin --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.2.1</version> <configuration> <warSourceDirectory>src/main/webapp</warSourceDirectory> <!-- war파일 디렉토리 --> <failOnMissingWebXml>false</failOnMissingWebXml> <!-- web.xml이 없을 때 에러를 낼건지 안낼건지 --> </configuration> </plugin> <!-- 기타 --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <excludes> <exclude> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </exclude> </excludes> </configuration> </plugin> </plugins> </build> </project>
web.xml 자동으로 생성하는 방법
프로젝트 우클릭 -> Java EE Tools -> Generate 클릭 ->
eclipse로 war 만들기
File -> New -> Export -> Web -> WAR file
프로젝트 우클릭 -> Run As -> Maven build -> Goals: clean package ->
참조:
https://limsungju.tistory.com/195
https://blog.naver.com/bb_/222325645171
3 . ★ package 메이븐 빌드시 에러 날경우 추가
<dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>2.3.0</version> </dependency> <dependency> <groupId>org.javassist</groupId> <artifactId>javassist</artifactId> <version>3.25.0-GA</version> </dependency> <dependency> <groupId>javax.persistence</groupId> <artifactId>javax.persistence-api</artifactId> <version>2.2</version> </dependency>
4. 자바로 만든 서버 파일이 ROOT.war 일때 이 war 를 실행하는 방법은 다음과 같다.
java -jar ROOT.war
백그라운드 실행이 안되므로 다음과 같이 start/stop.sh를 만든 후 실행
#sh start.sh
#sh sop.sh
[start.sh] nohup java -jar ROOT.war 2>&1 &
[stop.sh] pid=`ps -ef | grep ROOT.war | grep -v 'grep' | awk '{print $2}'` kill -9 $pid
기타 참조 :
https://ttuk-ttak.tistory.com/23
댓글 ( 7)
댓글 남기기