Wookim

maven multi module 본문

programming language/Java

maven multi module

개발자인 경우 2020. 5. 20. 17:27

회사에서 작업하던 java 프로젝트를 maven 프로젝트로 변환하는 업무를 맡았다.

생 java 프로젝트라 lib들을 파일로 관리하고 있어서... 

회사 내 nexus와 maven으로 lib를 관리하기로 결정했다.

 

상황은

core가 되는 프로젝트와

core에 jar로 말려들어가는 plugin들의 구조를 바로 잡아야 하는 것.

 

문제가 되는게 

core와 plugin들이 서로 circular dependency(상호 의존) 관계였던것..

(때문에 mavne build 과정 중 애를 많이 먹었다.)

 

해당 프로젝트들을 하나로 통합하고 

mavne multi module 프로젝트로 변환하기로 결정했다.

 

구조는 다음과 같다.

 

template (껍데기)

pom.xml 

---- common

---- pom.xml

---- engines

---- pom.xml

----- ---core

----- ---pom.xml

---- plugins

---- pom.xml

---- ---- plugin1

---- ---- pom.xml

---- ---- plugin2

---- ---- pom.xml

---- ---- plugin3

---- ---- pom.xml

---- release

---- pom.xml

 

처음보면 많이 복잡해 보이는데...

원리는 간단하다

 

template의 pom.xml 부터 프로젝트 내부의 pom.xml 들을 정해진 순서로 읽어가며 complie한다.

최종적으로 하나의 zip 파일을 배포한다.

 

 

?...

 

 

단계를 살펴보면

1. common          ->  common 프로젝트 complie -> jar, classfile 배포

2. plugins/plugin  -> 배포된 common을 참조하여 plugin프로젝트 complie -> jar, classfile 배포

3. engine/core     -> 배포된 common, plugin들을 참조하여 core프로젝트 complie -> jar, classfile 배포

4. release            -> 배포된 core.jar와 core가 의존하는 lib  -> 하나의 zip 파일로 배포

 

원하는 목표는 이렇고 조금더 세부적으로 설명을 하보겠다.

 

 


 

template의 pom.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>com.company.group</groupId>
    <artifactId>proejct</artifactId>
    <version>0.0.1</version>
    <!-- module들의 부모임을 명시  -->
    <packaging>pom</packaging>

    <!-- 변수 선언 -->
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <distributionManagement>
        <repository>
            <id>releases</id>
            <name>Internal Repository</name>
            <url>http://nexus.xxx.com</url>
        </repository>
    </distributionManagement>

    <!-- 자식 module 명시 -->
    <!-- 주의 순서 순으로 compile 및 package 실행됨 -->
    <modules>
        <!--  common : connectors, engine에서 참조함 -->
        <module>common</module>
        <!-- plugins folder : plugin 담는 부모 module -->
        <module>plugins</module>
        <!-- engine group folder : engine들을 담는 부모 module-->
        <module>engine</module>
        <!-- 단순 배포 역할만 하는 module -->
        <module>release</module>
    </modules>

    <build>
        <plugins>
            <!-- compile -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <!-- lib 의존성 설정 : 하위 모듈들은 해당 라이브러리 자동으로 참조됨-->
    <dependencies>
      <dependency>
          <groupId>${그룹아이디}</groupId>
          <artifactId>${아티팩트아이디}</artifactId>
          <version>${버전}</version>
      </dependency>
    </dependencies>
</project>

 

해당 파일은 굉장히 중요하다.

pom.xml의 최상위 부모가 되겠다. (super pom)

 

해당 pom.xml에서 자식들의 컴파일 순서를 결정하고

자식들이 공통적으로 참조하는 lib들을 

한곳에서 참조하는 역할을 한다.

 

위 파일에서 주의깊게 볼 태그들이다.

1. <packaging>pom</packaging>

2. <modules>

      <module>${자식의 아티팩트 아이디}</module>

  </modules>

3. <build> 의 내용은 전부 중요 </build>

4. <dependencies>....</dependencies>

 

1. 번 태그는 자신이 부모 pom파일이라는 것을 명시하는 것.

module을 담는 pom 파일은 해당 옵션이 무조건 pom이라는 것을 기억할것.

 

2. 번 태그는 해당 pom의 자식 모듈들을 명시하는 것.

<module> 태그 안에는 자식의 아티팩트 아이디를 넣을 것.

 

3. 번 태그는 build 옵션을 설정하는 태그인데... 아파치 공식 문서를 많이 읽어볼것...

부모 pom에서는 complie 옵션만 설정함. 여기서 설정한 complie 옵션은 자식들에서도 공통적으로 사용됨.

예외적으로 자식에서 다른 옵션으로 컴파일 하고 싶다면 자식에서 재정의하면 됨.

 

4. 번 태그는 라이브러리 의존성을 설정하는 태그.

최상위 부모에서 설정한 의존성은 자식 들도 의존함. 

 

즉 모듈들이 공통적으로 사용하는 라이브러리는 super pom에 정의하는게 편하다.

 

 

여기까지가 template의 super pom에대한 설명이다.

 


다음은

 

<modules>
        <module>common</module>
        <module>plugins</module>
        <module>engine</module>
        <module>release</module>

</modules>

 

에서 첫번째 common 모듈(자식) 프로젝트 pom에 대해 알아보자

 

<?xml version="1.0" ?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <!-- 부모 명시 : sub module임을 명시 -->
    <parent>
        <!-- 부모의 그룹, 아티팩트, 버전 명시 -->
        <groupId>com.company.group</groupId>
        <artifactId>template</artifactId>
        <version>0.0.1</version>
    </parent>
    <!-- 자기 자신 명시 -->
    <!-- 자기 자신의 그룹아이디는 
         부모의 그룹아이디 + 아티팩트아이디 로 구성해야 
         nexus랑 연동할 때 폴더 구조가 이쁘게 나온다. -->
    <groupId>com.company.group.template</groupId>
    <artifactId>common</artifactId>
    <version>0.0.1</version>
    <!-- packaging 방식 선언 -->
    <packaging>jar</packaging>
    <!-- 이름 -->
    <name>common</name>

    <build>
        <!-- java 소스 경로 위치 명시 -> jar에 class 위치하도록 -->
        <sourceDirectory>src/</sourceDirectory>
        <!-- resource 경로는 다른 프로젝트에서 설명 -->
        <resources></resources>
        <plugins>
            <plugin>
                <!-- mavne jar plugin -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.2</version>
                <!-- 설정 정보 -->
                <configuration>
                    <archive>
                        <manifest>
                            <!-- jar로 package 될 때 classpath 추가 옵션 -->
                            <addClasspath>true</addClasspath>
                            <!-- 사용되는 라이브러리나 모듈들의 경로를 lib 디렉토리로 설정 -->
                            <classpathPrefix>src</classpathPrefix>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

common의 pom.xml은 위처럼 구성했다.

 

살펴볼 태그는

  1. <parent>
  2. <packaging>
  3. <build>

정도 되겠다.

 

1. <parent> 태그는 자신의 부모를 명시 함.

부모 pom의 정보를 작성할것.

 

2. <packaging> 태그는 배포될 형식.

pom이 아닌 jar라는 것을 주목할것.

해당 pom파일을 build 하면 jar로 배포됨.

 

3. <build> 태그에서 mavne-jar-plugin이라는 것을 사용함.

쉽게 말해 프로젝트를 jar로 말아주는 역할을 함.

모듈끼리 참조되는 프로젝트라면 <addClasspath>와 <classpathPrefix>옵션을 유심히 살펴볼것.

(ide에서 실행하는 것이 아닌, jar로 실행할 때, classpath 정보가 있어야 참조 가능하다.)

 


다음은 plugins를 살펴 보자.

 

<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>
    <!-- 부모 명시 : sub module임을 명시 -->
    <parent>
        <groupId>com.company.group</groupId>
        <artifactId>proejct</artifactId>
        <version>0.0.1</version>
    </parent>
    
    <!-- 자신의 정보 명시 -->
    <groupId>com.company.group.project</groupId>
    <artifactId>plugins</artifactId>
    <packaging>pom</packaging>

    <!-- sub module들 명시 : 해당 sub module들의 부모임을 명시  -->
    <modules>
        <!-- 해당 모듈 순으로 complie 및 packaging 됨 -->
        <module>plugin1</module>
        <module>plugin2</module>
        <module>plugin3</module>
        <module>plugin4</module>
    </modules>

</project>

 

이건 세상 간단하다.

 

plugins의 pom은 plugin들의 부모역할을 함.

 

template -> plugins -> plugin

요런 계층 구조라 보면됨.

 

해당 pom은 parent에 tempalte을 명시했고 modules에 plugin들을 명시함.

template를 부모로 두며 plugin 자식들이 있다 라고 생각.

 

자세한 설명은 template과 중복되므로 생략함.

 


다음은 plguin1 만 살펴보자.

 

<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>
    <!-- 부모 명시 : sub module임을 명시 -->
    <parent>
        <groupId>com.company.group.project</groupId>
        <artifactId>plugins</artifactId>
        <version>0.0.1</version>
    </parent>

    <!-- 자신 정보 명시 -->
    <groupId>com.company.group.project.plugins</groupId>
    <artifactId>plugin1</artifactId>
    <packaging>jar</packaging>

    <!-- resource 경로 설정 -->
    <build>
        <resources>
            <resource>
                <directory>{resource 폴더 경로}</directory>
                <includes>
                    <!-- 포함할 파일 명시 (mybatise.xml 파일들) -->
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
        <!-- java 소스 경로 위치 명시 -> jar에 class 위치하도록 -->
        <sourceDirectory>src/</sourceDirectory>
        <plugins>
            <plugin>
                <!-- mavne jar plugin -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.2</version>
                <!-- 설정 정보 -->
                <configuration>
                    <archive>
                        <manifest>
                            <!-- jar로 package 될 때 classpath 추가 옵션 -->
                            <addClasspath>true</addClasspath>
                            <!-- 사용되는 라이브러리나 모듈들의 경로를 lib 디렉토리로 설정 -->
                            <classpathPrefix>src</classpathPrefix>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <!-- super pom.xml에서 제일먼저 complie한 공통 모듈을 참조 -->
    <dependencies>
        <dependency>
            <groupId>com.company.group.template</groupId>
            <artifactId>common</artifactId>
            <version>0.0.1</version>
        </dependency>
    </dependencies>
</project>

plugins를 부모로 둔 모듈이다.

 

*중요 포인트1 <build>하위 태그들

<resource> : 소스 이외에 사용하는 파일

<directory> : 위 파일들을 저장하는 폴더 경로

<include> :  jar에 포함할 resource 파일 양식 설정

                 이는 resource 하위 폴더 구조와 .xml 파일이 jar에 같이 말리도록 설정한 것이다.

<sourceDirectory> : java 코드가 있는 경로 설정.

                           해당 plugin1은 core.jar에서 사용하는 lib이다.

                           source, resource 경로를 설정해야 core.jar가 실행 될 때,

                           해당 파일들(plugin1의 xml, class파일들)을 찾을 수 있다.

 

*중요 포인트3 <dependency>

앞서 complie한 common모듈을 참조하고 있다.

 


engines의 pom의 역할은 plugins의 pom과 같다.

글을 이해하고 따라왔다면 쉽게 만들수 있으므로 생략.


다음은 제일 중요한 core에 대해 알아보자.

 

core 프로젝트는

프로세스 진입점인 main 클래스가 있는 jar다.

따라서 core 프로젝트가 말그대로 "핵심"이며 

앞서 complie한 jar들을 사용한다.

 

따라서 프로젝트들 중 가장 늦게 complie 해야 한다.

 

...?

 

더보기

만약 core먼저 complie하면 core를 complie 하기위해 참조되는

plugin들의 class파일이 없어서 컴파일 에러가 난다.

core의 pom 파일이다.

<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>
    <!-- 부모 명시 : sub module임을 명시 -->
    <parent>
        <groupId>com.company.group.project</groupId>
        <artifactId>engine</artifactId>
        <version>0.0.1</version>
    </parent>
    <!-- 자신 정보 명시 -->
    <groupId>com.company.group.project.engine</groupId>
    <artifactId>core</artifactId>
    <!-- package 설정 -->
    <packaging>jar</packaging>
    <name>core</name>

    <!-- 변수 선언 -->
    <properties>
        <mainClassPath>{메인 class 파일 경로}}</mainClassPath>
    </properties>

    <!-- 빌드 옵션 설정 -->
    <build>
        <!-- resource를 classpath로 설정 -->
        <resources>
            <resource>
                <directory>{resource 폴더 경로}</directory>
                <includes>
                    <!-- 포함할 파일 명시 (mybatise.xml 파일들) -->
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <!-- mavne jar plugin -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.2</version>
                <!-- 설정 정보 -->
                <configuration>
                    <archive>
                        <manifest>
                            <!-- jar로 package 될 때 classpath 추가 옵션 -->
                            <addClasspath>true</addClasspath>
                            <!-- public static void main() 함수가 있는 클래스 지정 -->
                            <mainClass>${mainClassPath}</mainClass>
                            <!-- 사용되는 라이브러리나 모듈들의 경로를 lib 디렉토리로 설정 -->
                            <classpathPrefix>lib</classpathPrefix>
                        </manifest>
                        <!-- conf 폴더에 담은 설정 파일들을 classpath에 추가 -->
                        <!-- 해당 옵션을 주지 않으면 core.jar를 실행 할 때 conf폴더에 있는 설정을 읽지 못함 -->
                        <manifestEntries>
                            <Class-Path>conf/</Class-Path>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <!-- super pom.xml에서 complie한 common, connectors의 module들을 참조 -->
    <dependencies>
        <dependency>
            <groupId>com.company.group.template</groupId>
            <artifactId>common</artifactId>
            <version>0.0.1</version>
        </dependency>
        <dependency>
            <groupId>com.company.group.project.plugins</groupId>
            <artifactId>plugin1</artifactId>
            <packaging>jar</packaging>
        </dependency>
        <dependency>
            <groupId>com.company.group.project.plugins</groupId>
            <artifactId>plugin2</artifactId>
            <packaging>jar</packaging>
        </dependency>
        <dependency>
            <groupId>com.company.group.project.plugins</groupId>
            <artifactId>plugin3</artifactId>
            <packaging>jar</packaging>
        </dependency>
        <dependency>
            <groupId>com.company.group.project.plugins</groupId>
            <artifactId>plugin4</artifactId>
            <packaging>jar</packaging>
        </dependency>
    </dependencies>
</project>

중복되는 설명은 생략하고 중요포인트만 살펴보자.

 

1. <mainClasspath> 태그에 main class 파일의 경로를 설정해야 한다. -> 진입점 명시 : 실행가능한 jar로 배포하기

 

2. <manifestEntries> 태그에 conf/ 라는 폴더 경로를 설정했다.

core 프로젝트의 conf 폴더에는 .properties와 .xml 파일들이 존재하며, mybatis 설정 파일 및 db 접속정보 저장한다.

해당 파일들은 실행 시점 core.jar가 참조할수 있도록 <manifestEntires>태그에 해당 폴더 경로를 설정했다.

다만 jar안에 conf 폴더가 같이 말리지 않는다. (실행가능한 jar가 conf폴더를 참조할수 있도록 설장하는것.

resouce 태그와 혼동하지 말것!)

 

3. dependecy를 보면 앞서 complie한 프로젝트들을 참조하고 있다.

core.jar에서 앞서 complie한 프로젝트들을 사용하므로 

dependency를 걸어야 한다.

 

그렇게 하면 core를 complie할 때 사용하고 있는 jar들의 정보를 참조할 수 있기 때문이다.

 

하지만, 위 설정으로 core를 complie해도 참조하는 lib들이 core.jar에 없다.

 

...?


그렇다면 어떻게 해야하나?...

 

이를 해결하기 위한 프로젝트가 release 프로젝트다.

 

 

release 프로젝트의 소스코드는 단 한줄도 없다.

오직 위 프로젝트들을 하나의 zip 파일로 (어벤져스~) Assemble 하기위해 존재한다.

 

이게 무슨 소리인가 하면...

 

각각의 프로젝트는 각각 complie되며 jar로 각각 배포된다.

즉 각 프로젝트 jar는 온전히 자기 자신만 존재한다. (참조 관계만 기술 될 뿐)

 

이는 각 프로젝트를 nexus에 각각 올리기 위해서다. 

(각 모듈이 참조하는 lib들 모두가 jar에 말려있다면.. 중복되고...용량은 커질뿐....)

 

따라서

진입점인 core.jar실행 가능하게 하려면,

core.jar와 plugin들의 jar, 그리고 참조중인 다른 jar들이 참조할수 있는 경로에 있어야 한다.

 

zip file

---- core.jar

---- plugin1.jar

---- plugin2.jar

---- plguin3.jar

---- plugin4.jar

---- 참조하는 lib1.jar

---- 참조하는 lib2.jar

...

 

대충 이런식으로 jar파일들이 모여 있어야 core.jar가 실행할때 참조 가능하다.

 

이를 mavne build 단계에서 처리하기 위한 프로젝트가 release 프로젝트라 보면된다.

 

(설명이 길었는데 맞게 설명했는지, 이해하기 쉬운지는 잘 모르겠다... 피드백은 감사히 받겠습니다.)

 

 

release 프로젝트는 3가지로 구성되어 있다.

1. pom.xml

2. assembly.xml

3. conf 폴더

 

프로젝트 구조는 

이렇게 구성했다.

 

원하는 바는 다음과 같다

 

zip (파일로 배포)

---- conf (설정정보 폴더 .xml, .properties...)  

---- lib (plugin jar들 및 참조하는 외부 jar들)

---- core.jar

---- start.sh

---- start.bat

 

위 구조로 zip 파일 하나만 배포하려 한다.

 

먼저 pom.xml 파일이다.

<?xml version="1.0" ?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <!-- 부모 참조 : sub module임을 명시 -->
    <parent>
        <groupId>com.company.group</groupId>
        <artifactId>proejct</artifactId>
        <version>0.0.1</version>
    </parent>

    <!-- 자신 정보 명시 -->
    <groupId>com.company.group.project</groupId>
    <artifactId>release</artifactId>
    <packaging>pom</packaging>
    <version>0.0.1</version>
    <name>release</name>

    <!-- assembly -->
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>engine-core</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <!-- release 프로젝트 위치한 assembly.xml파일 : 어셈블리 옵션 설정 -->
                                <descriptor>src/assemble/assembly.xml</descriptor>
                            </descriptors>
                            <finalName>{zip 파일 이름}</finalName>
                            <archive>
                                <manifest>
                                    <!-- classpath 추가 하도록 설정 -->
                                    <addClasspath>true</addClasspath>
                                </manifest>
                            </archive>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <!-- 해당 pom에서 필요한 jar는 core.jar이므로 의존성 명시 -->
    <dependencies>
        <dependency>
            <groupId>com.company.group.project.engine</groupId>
            <artifactId>core</artifactId>
            <version>0.0.1</version>
        </dependency>
    </dependencies>
</project>

위 pom 파일의 build 내용은 잘모르면 그대로 유지할것...

 

중요 태그 1

<build>에 maven-assembly-plugin을 사용한다는 것!

 

<executions> 아래 id, phase, goals 등등을 적어주자...

<id>는 적당히 쓰고,,,

<pahse>는 mavne의 작업 단계를 의미한다.

<descriptor> assembly.xml 파일의 위치경로를 적으면 된다

 

이부분은 필자의 설명보다 아파치 공식 문서를 읽는게.... 

https://maven.apache.org/plugins/maven-assembly-plugin/usage.html

 

 

중요 태그 2

<dependency>에 core를 의존한것을 볼것.

실행 할 jar가 core고,

core를 의존하면 ,

core가 참조하는 lib들은 알아서 참조된다.

 

즉 핵심은 core를 의존하는 것.

 


자... assembly.xml이다

 

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>bin</id>
    <!-- 배포할 양식 -->
    <formats>
        <format>zip</format>
        <format>tar.gz</format>
    </formats>

    <!-- 설정 정보를 담는 파일(xml, propeties) 저장하도록 설정 -->
    <fileSets>
        <!-- release 프로젝트의 conf 폴더 안 .xml, .properties 파일들을 
             zip 안 conf 폴더로 배포함 -->
        <fileSet>
            <directory>${basedir}/conf</directory>
            <includes>
                <include>**/*.xml</include>
                <include>**/*.properties</include>
            </includes>
        </fileSet>
    </fileSets>

    <!-- dcs의 core.jar파일은 lib 폴더가 아닌 root path에 위치시키는 설정 -->
    <dependencySets>
        <dependencySet>
            <!-- jar들이 배포되는 위치 -->
            <outputDirectory>lib</outputDirectory>
            <excludes>
                <!-- engine.core의 core.jar는 lib 폴더에 제외 -->
                <!-- 경로는 다음처럼 구성 : groupId:artifactId -->
                <exclude>com.company.group.project.engine:core</exclude>
            </excludes>
        </dependencySet>
        <dependencySet>
            <!-- core.jar가 배포되는 위치 -->
            <outputDirectory>/</outputDirectory>
            <includes>
                <!-- engine.core의 core.jar는 zip의 root path에 위치하도록 설정 -->
                <!-- 경로는 다음처럼 구성 : groupId:artifactId -->
                <include>com.company.group.project.engine:core</include>
            </includes>
        </dependencySet>
    </dependencySets>
</assembly>

웬만하면 그대로 유지하면 된다.

 

중요 태그1

<formats> 배포할 파일 양식을 설정한다

 

중요 태그2

<fileSets> zip안에 같이 포함할 soruce 이외의 파일들을 명시한다. 

 

중요 태그3

<dependencySet> release의 pom이 의존하는 라이브러리들을 명시한 <outputDirectory> 경로에 복사한다.

 

중요 태그4

<excldues>와 <includes> 

 

core.jar는 lib 폴더에 위치 시키고 싶지 않았다.

따라서 lib 패스에 <exclude> 시켜줬다.

 

다음 core.jar는 zip의 root 경로에 위치시키기 위해 

dependency와 output 경로를 추가한 후

<include>했다.

 

이제 설정은 잘 마치고 

template( 최상위 pom.xml)을 mavne build하면

 

요러커니 release 프로젝트의 target 폴더에 zip파일이 배포된다.

zip파일을 까보자

요로코롬 나왔다.

 

해당 경로에서 cmd창을 킨다음 

java -jar core-0.0.1.jar 

명령어를 치면 해당 jar가 실행된다.

 

TMI

더보기

배포된 conf 폴더는 release 프로젝트의 conf 폴더다 

core의 conf폴더가 아니다.!

주의 할것.

 

이는 개발할 때 ide에서 core를 실행시킬때 conf가 필요하여 

core 프로젝트에 conf가 따로 저장한것이다. (개발 할 때 사용을 위해)

 

release의 conf 폴더는 배포할 때 zip에 끼워넣기 위해  (운영 시 사용을 위해)

위치한것이다.

 

같은 내용의 폴더이지만, 각각 관리된다는 것을 주의할것!

zip에 conf는 release의 conf 폴더라는 것!

 

긴글 읽으시느라 고생하셨습니다...

도움이 되셨는지 모르겠네요.

 

처음 maven pom파일을 밑바닥 부터 작성해봤는데...

이해하는 과정이 순탄치 않았네요.

 

누군가는 저보다 삽질을 좀 덜하길 빌며 

예제를 작성해봤습니다.

 

도움이 되었다면 

좋겠네요.

 

감사합니다~

 

Comments