And then I have to use the Akka Microkernel.
Not that this is bad news. The bad news is that I have to do it with maven. The project I’m doing this for is already using maven, and has a few modules – which makes migrating to sbt out of question. Akka has a nice sbt plugin that generates the package for a microkernel distribution of your akka project – but there is no such thing for maven.
How to solve this problem with maven? Fortunately, it isn’t that hard. There are probably lots of other ways to do it, but my solution will use the maven-assembly-plugin. The boring part, as always with maven, is to write the proper xml. I’ve created a new assembly descriptor, called akka.xml, that goes as follows:
<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>akka</id> <formats> <format>zip</format> </formats> <fileSets> <fileSet> <directory>${project.build.directory}</directory> <outputDirectory>/deploy</outputDirectory> <includes> <include>*.jar</include> </includes> </fileSet> </fileSets> <dependencySets> <dependencySet> <outputDirectory>/lib</outputDirectory> </dependencySet> </dependencySets> <files> <file> <source>src/main/resources/akka/start</source> <outputDirectory>/bin</outputDirectory> </file> <file> <source>src/main/resources/akka/application.conf</source> <outputDirectory>/config</outputDirectory> </file> </files> </assembly>
Two points to notice: the xml assumes an akka start script at src/main/resources/akka/start and a configuration file at src/main/resources/akka/application.conf, so you will have to create those. For me, I just copied the default start generated by the akka sbt plugin and created an empty application.conf, and will tweak them later.
Now, to enable the plugin add the following to the plugins section of your pom.xml:
<plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.3</version> <configuration> <descriptors> <descriptor>src/main/assembly/akka.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>
This one also assumes something: the presence of the previous xml code, in the folder src/main/assembly/akka.xml.
That should do it! Now just unpack the zip file in your server and run your Bootable akka code =]
EDIT:
Since the xml mentioned above went through small tweaks, I added them in this GIST. So if you want to see the most recent version, go there 😉
Excellent post, worked for me.
That is a good post and appreciate it. I have tried to run the example but looks like I am getting some not exactly write. After creating the descriptor xml and updating the POM.xml , I runed the mvn assembly: asselby plugin. then maven complains that the start script is not a file. the start file am using is a batch file i copied from the akka examples from the git source.
Is there any suggestion for me..
From your description of the problem, my guess is that your assembly is not even finding the start script file.
Yes ,, that will be the likely problem.. I have given a description of the problem at the following stackoverflow link http://stackoverflow.com/questions/13269293/distributing-the-akka-micro-kernel-application-with-maven/13269633#13269633
hope it will clarify the problem. Will be happy of know if there Is a workaround. Thanks.
I added an answer there =)
thanks for the suggestion. my application now works .
I have tried the tutorials in this blog. When I check the zip package after running the assembly:single plugin goal or the package command from the maven , the deploy folder does not get created, only the lib, config and the bin folders are created. Was thinking that the deploy directory will also be created. Don’t know whether am right. Will be glad for an clarification.
I have tried the tutorials on this blog. After using the assembly:assembly goal or package command , maven creates the lib, bin and config directories in te zip package but does not crate a deploy directory. but looks like from the Akka.xml descriptor file the assembly plugin is also expected to create a deploy directory. Looks like I might be missing something. Will be very happy for a clarification.
If I remember correctly, it should create the deploy folder and copy jar files to it. But its been a long time and I might be misremembering that …
looks like what I have is that maven copies all the jar files into the lib folder this includes the application that is developed to run on top of the akka microkernel
was able to make maven create the deploy folder with the application developed as a jar file in the folder
Thanks for the post. Works flawlessly!!
these instructions worked just fine for me too on scala 2.10, akka 2.1.2. thanks OP!