Monday, December 1, 2008

maven: working with manifests (MANIFEST.MF)

mในกรณีการทำ excution jar จะต้องมีการกำหนด main-class ,classpath ใน /META-INF/MANIFEST.MF
เพื่อให้สามารถรันได้ maven จะช่วยให้ง่ายขึ้น
ตัวอย่าง แก้ไขไฟล์ pom.xml โดยเพิ่ม plugin ดังนี้
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<configuration>
<archive>
<manifest>
<mainClass>com.gosoft.app.App</mainClass>
<packageName>com.gosoft.app</packageName>
<addClasspath>true</addClasspath>
<addExtensions />
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
<mode>development</mode>
<url>ddddd</url>
</manifestEntries>
</archive>
</configuration>
</plugin>

maven: copy libraries to classpath

การเพิ่มคำสั่งให้ maven copy library ที่ dependencies ไปยัง target path ที่ทำการ package .jar ของเราเอาไว้
ตัวอย่าง แ้ก้ไขที่ pom.xml เพิ่ม plug-in ที่ช่วย copy library ไปยัง targetpath
.......
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNever>true</overWriteIfNever>
</configuration>
</execution>
</executions>
</plugin>
.......