[Maven] Executable jar + Assembly 를 이용한 tar 묶기.
ITWeb/개발일반 2015. 9. 22. 12:29main 함수 만들고 executable jar로 만들기 위해서 일반적인 패키징 작업중 하나 입니다.
그냥 또 기억 못할까봐 정리해 봅니다.
기본적인 내용이 자세한 내용과 활용은 아래 링크 참고하세요.
Ref.
https://maven.apache.org/plugins-archives/maven-assembly-plugin-2.5.4/
https://maven.apache.org/plugins/maven-assembly-plugin/assembly-mojo.html
[pom.xml 에 maven assembly plugin 추가 하기]
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<index>false</index>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${MAINCLASS}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptors>
<descriptor>src/main/assemblies/package.xml</descriptor>
</descriptors>
<finalName>${project.name}</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>tarball</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
[assembly 생성하기]
- src/main/assemblies/package.xml
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.
1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>tarball</id>
<formats>
<format>tar</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>bin/*.sh</include>
<include>lib/sigar/*.so</include>
<include>lib/sigar/*.dylib</include>
<include>lib/sigar/*.dll</include>
<include>lib/sigar/*.lib</include>
</includes>
</fileSet>
</fileSets>
</assembly>
참 쉽죠!!
이렇게 만들어서 생성을 하게 되면 최종 tarball 은 아래와 같은 형태로 만들어 집니다.
${project.name}.tar
- 여기서 <finalName>과 <appendAssemblyId> 설정에 따라 finalName으로 이름이 적용 되게 됩니다.