Friday, September 21, 2012

Maven - generate executable jar file

Recently I started to work a bit more with scala again and also finally upgraded to my new nemesis, maven3. More torture than maven2, but I could not live without it.

So what I wanted todo is rather simple, build an archive containing all my classes, a generated manifest and make it executeable.

10 minutes later we found the solution:



<plugin> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <id>convert-to-asci</id> <phase>package</phase> <goals> <goal>single</goal> </goals> <configuration> <archive> <manifest> <mainClass>edu.ucdavis.fiehnlab.alchemy.core.process.util.ConvertMZXmlToAscii</mainClass> <packageName>edu.ucdavis.fiehnlab.alchemy.core.process.util</packageName> <addClasspath>true</addClasspath> </manifest> </archive> <descriptors> <descriptor>src/main/descriptor/jar.xml</descriptor> </descriptors> <finalName>ConvertMzXmlToASCII-${project.version}</finalName> <appendAssemblyId>false</appendAssemblyId> </configuration> </execution> <execution> <id>alchemy-converter-zip</id> <phase>package</phase> <goals> <goal>single</goal> </goals> <configuration> <descriptors> <descriptor>src/main/descriptor/zip.xml</descriptor> </descriptors> <attach>true</attach> <finalName>alchemy-converter-${project.version}</finalName> </configuration> </execution> </executions> </plugin> The important part is to set the appendAssembyId to false, otherwise you get all kinds of annoying exceptions....