我有一个 Akka 独立项目
实现微内核的 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>
使用这个插件,我们将所有必要的文件复制到目标文件中。
现在我们使用带有descriptor.xml 文件的程序集插件将目标文件的内容复制到一个zip 文件夹。下面是descriptor.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 文件并单击。