• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    해결됨

user-service-1.0.jar 파일이 정상적으로 만들어지지 않습니다.

21.08.12 20:19 작성 조회수 609

0

안녕하세요.

강의 9:41의 결과처럼 /user-service-1.0.jar 을 만들어

docker run 을 정상적으로 실행시키려고 합니다.

하지만 정상적인 jar 파일이 만들어지지 않고 아래처럼 종속성이 빠진 상태로 33KB로 만들어집니다.  user-service-1.0.jar.original과 비슷한 파일 크기 입니다. 

그래서 저는 아래의 화면처럼 Build Artifact를 진행해 의존성이 포함된 user-service-1.0.jar 만들어봤지만 no main manifest attribute, in userservice.jar 에러가 떠서 

/resources/META-INF/MANIFEST.MF 파일을 만들었습니다.

Manifest-Version: 1.0
Main-Class: com.example.userservice.UserServiceApplication

위 소스처럼 MANIFEST.MF 를 만들고 진행을 하면 

docker run ***/user-service:1.2
Error: Could not find or load main class com.example.userservice.UserServiceApplication
Caused by: java.lang.ClassNotFoundException: com.example.userservice.UserServiceApplication

위와 같은 에러를 보여 도저히 진행이 되지 않습니다.

아래는 macOS BigSur 의 bash_profile 설정입니다.

export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
export PATH=${PATH}:$JAVA_HOME/bin
export PATH=${PATH}:/usr/local/bin:/usr/local/bin/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
export CLASSPATH=$JAVA_HOME/lib:.

혹시나 해서 pom.xml 파일을 수정해도 마찬가지입니다.

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>user-service</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>user-service</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<spring-cloud.version>2020.0.2</spring-cloud.version>
<org.mapstruct.version>1.4.2.Final</org.mapstruct.version>
<org.projectlombok.version>1.18.16</org.projectlombok.version>
<lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.176</version>
<!-- <scope>test</scope> test일 경우 실행결과를 확인 할수 없음 -->
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>2.3.8</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<!-- <version>2.4.4</version>-->
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>

<!-- Feign Client -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

<!-- resilience4j -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
</dependency>

<!-- slueth -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>

<!-- zipkin -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
<version>2.2.3.RELEASE</version>
</dependency>

<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source> <!-- or higher, depending on your project -->
<target>${java.version}</target> <!-- or higher, depending on your project -->
<!-- See https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html -->
<!-- Classpath elements to supply as annotation processor path. If specified, the compiler -->
<!-- will detect annotation processors only in those classpath elements. If omitted, the -->
<!-- default classpath is used to detect annotation processors. The detection itself depends -->
<!-- on the configuration of annotationProcessors. -->
<!-- -->
<!-- According to this documentation, the provided dependency processor is not considered! -->
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${org.projectlombok.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>${lombok-mapstruct-binding.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-Amapstruct.suppressGeneratorTimestamp=true</arg>
<arg>-Amapstruct.defaultComponentModel=spring</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>


위는 pom.xml 설정이고 mapstruct 과 lombok을 함께 사용하기 위해 maven-compiler-plugin을 spring-boot-maven-plugin과 함께 사용했습니다.
혹시나 하는 마음에 
maven-compiler-plugin빼고 mvn clean compile package -DskipTests=true 해도 마찬가지였습니다.

어떻게 하면 정상적으로 jar파일을 이용해서 이미지를 만들어 docker run을 진행해볼수 있을까요?

답변 1

답변을 작성해보세요.

2

안녕하세요, 이도원입니다. 

보내주신 오류 메시지를 바로 재현해 볼 수 없어서, 정확한 해결책은 드리기 어려울 것 같습니다. 다만, pom.xml 파일에서 아래와 같이 <pluginManagement>를 사용하셨는데, Parent POM과 Child POM 관계에서 Child POM 필요한 설정을 지정하고자 할 때 사용합니다. Parent - Child 설정이 아니라면 삭제하는 것이 맞다고 생각됩니다.

  <build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

보내주신 pom.xml 파일을 제가 가지고 있는 user-service에 적용해 보았을 때는 아래와 같은 오류가 발생하지만, <pluginManagement>를 삭제하고 실행하면 정상적으로 실행되었습니다. <pluginManagement> 삭제하고 빌드해 보시기 바랍니다. 

감사합니다. 

blue-sky님의 프로필

blue-sky

질문자

2021.08.13

우와~ 잘 됩니다.
이것때문에 며칠 삽질했는데..감사합니다.