繁体   English   中英

如何打包Akka项目

[英]How to package an Akka project

我有一个Akka独立项目

实现mico内核的Bootable接口

有关使用微内核处理Akka系统的教程

描述了一个使用sbt插件的SBT项目

可以告诉我如何用微内核打包Maven项目

在Google上搜索“ akka microkernel maven”,将其列为您的问题的最有争议的答案之一: http : //jcranky.com/2012/07/13/akka-microkernel-with-maven/

在浏览了JCrnak的博客并阅读了maven程序集插件和清单文件文档之后,我能够提出一个与JCranky略有不同的解决方案,并希望与大家分享。

第一个假设是,所有Akka插件(包括微内核的插件)都已在POM.xml中配置。 其次,已经开发了要分发的应用程序。

maven软件包阶段将创建一个可执行的jar文件。 但是,这需要使用java -jar命令直接执行应用程序的主类。 为了使包应用程序知道主类的位置,我们将以下插件与清单文件的配置一起插入POM.xml中。

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>com.bbox.gesture.BoundingBox</mainClass> 
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

要将akka依赖项复制到目标文件中的lib文件中,我们添加以下插件。

  <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>
                          ${project.build.directory}/lib
                        </outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>

使用此插件,我们将所有必需的文件复制到目标文件。

现在,我们使用带有描述符.xml文件的程序集插件将目标文件的内容复制到zip文件夹中。 以下是描述符.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>akka</id>

  <formats>
    <format>zip</format>
  </formats>

  <fileSets>
    <fileSet>
      <directory>${project.build.directory}</directory>
      <outputDirectory>/deploy</outputDirectory>
      <includes>
        <include>**</include>
      </includes>
      <excludes>
          <exclude>*.jar</exclude>
          <exclude>*.zip</exclude>
      </excludes>
    </fileSet>
  </fileSets>


    <files>
        <file>
            <source>target/com-bbox-gesture-1.0-SNAPSHOT.jar</source>
            <outputDirectory>/deploy</outputDirectory>
            <destName>bbox.jar</destName>
        </file>

    <file>
      <source>src/main/resources/application.conf</source>
      <outputDirectory>/deploy/config</outputDirectory>
    </file>
  </files>

</assembly>

要运行程序集插件,我们将以下内容添加到POM.xml中

 <plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.3</version>
  <configuration>
    <descriptors>
      <descriptor>/descriptor.xml</descriptor>
    </descriptors>
  </configuration>

  <executions>
    <execution>
      <id>make-assembly</id>
      <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
    </execution>
  </executions>
</plugin>  

最重要的是,我们通过从部署目录开始运行java -jar命令,添加了一个简单的批处理文件来启动应用程序。 以下是批处理文件中的简单脚本

echo off  
cls  
start java -jar bbox.jar

start命令在可执行jar文件上运行java -jar命令。 bbox.jar文件是可执行的jar

要运行该应用程序,只需解压缩服务器中的zip文件夹,然后导航到start.bat文件并单击。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM