'2012/10/25'에 해당되는 글 1건

  1. 2012.10.25 maven으로 의존 lib들과 함께 java application package 방법


maven으로 의존 lib들과 함께 java application package 방법


java application package 방법


1. executable jar with dependencies

=> 의존 lib들을 .class 파일로 하나의 jar 파일 안에 package 


# maven-assembly-plugin

- 의존 lib들중 menifest (namespace) 파일이 겹치는 경우 가장 마지막 것만 남음


			<plugin>

				<groupId>org.apache.maven.plugins</groupId>

				<artifactId>maven-assembly-plugin</artifactId>

				<version>2.2.1</version>

				<configuration>

					<descriptorRefs>

						<descriptorRef>jar-with-dependencies</descriptorRef>

					</descriptorRefs>

					<archive>

						<manifest>

							<mainClass>com.stewie.test.Main</mainClass>

						</manifest>

					</archive>

				</configuration>

				<executions>

					<execution>

						<phase>package</phase>

						<goals>

							<goal>assembly</goal>

						</goals>

					</execution>

				</executions>

			</plugin>


# maven-shade-plugin

- 설정으로 manifest 파일을 append하여 namespace 문제 해결 가능


<예제>

			<plugin>

				<groupId>org.apache.maven.plugins</groupId>

				<artifactId>maven-shade-plugin</artifactId>

				<version>1.7.1</version>

				<executions>

					<execution>

						<phase>package</phase>

						<goals>

							<goal>shade</goal>

						</goals>

						<configuration>

							<transformers>

								<transformer

									implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">

									<mainClass>com.stewie.test.Main</mainClass>

								</transformer>

								<transformer

									implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">

									<resource>properties.properties</resource>

								</transformer>

								<transformer

									implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">

									<resource>applicationContext.xml</resource>

								</transformer>

							</transformers>

						</configuration>

					</execution>

				</executions>

			</plugin>



2. /${dist}.jar , /lib, /bin 형태의 tar로 package 방법


# maven-assembly-plugin 사용


		<plugins>

			<plugin>

				<artifactId>maven-assembly-plugin</artifactId>

				<executions>

					<execution>

						<id>distribution-assembly</id>

						<phase>package</phase>

						<goals>

							<goal>single</goal>

						</goals>

						<configuration>

							<descriptors>

								<descriptor>assembly/assembly.xml</descriptor>

							</descriptors>

							<finalName>${filename}</finalName>

							<appendAssemblyId>false</appendAssemblyId>

						</configuration>

					</execution>

				</executions>

			</plugin>

		</plugins>

- 필요한 descriptor 예시 (참조 : http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html)


<?xml version="1.0" encoding="UTF-8"?>

<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>zip</id>

	<formats>

		<format>tar</format>

	</formats>

	<includeBaseDirectory>false</includeBaseDirectory>



	<dependencySets>

		<dependencySet>

			<includes>

				<include>.....</include>

        ..

        ..

			</includes>

			<outputDirectory>lib</outputDirectory>

			<unpack>false</unpack>

		</dependencySet>

	</dependencySets>

	<fileSets>

		<fileSet>

			<directory>${basedir}</directory>

			<outputDirectory>/</outputDirectory>

			<includes>

				<include>**/*.jar</include>

			</includes>

		</fileSet>

	</fileSets>

</assembly>


// 사족으로 moduleset은 생각보다 작동이 션찮다

신고
Posted by Stewie


티스토리 툴바