创建可以在 Linux 上使用“服务”运行的 Java 应用程序的最佳方法是什么?我打算使用此处提供的 JSW ,但不能使用该许可证(许可证是 GPL 或据我所知它需要花钱)。我需要一个 apache 风格的许可证。
我正在使用 maven 构建,所以如果可以使用 maven 插件创建服务会很棒,但任何其他建议都会很棒。
我看过Apache Commons Daemon,是否有一个 maven 插件?文档似乎很少,所以这个工作的例子会很好......
谢谢
IT小君
2021-11-11T08:28:58 创建可以在 Linux 上使用“服务”运行的 Java 应用程序的最佳方法是什么?我打算使用此处提供的 JSW ,但不能使用该许可证(许可证是 GPL 或据我所知它需要花钱)。我需要一个 apache 风格的许可证。
我正在使用 maven 构建,所以如果可以使用 maven 插件创建服务会很棒,但任何其他建议都会很棒。
我看过Apache Commons Daemon,是否有一个 maven 插件?文档似乎很少,所以这个工作的例子会很好......
谢谢
IT小君 据我所知,Apache Daemon 或Akuma都没有 Maven 插件。尽管您可以尝试使用maven-exec-plugin从 Maven 构建中调用它们。
至于贵公司对使用 GPL 许可产品的保留意见,则值得仔细阅读使用的含义。它并不像企业所担心的那样具有毒性。这是GPL的解释。它当然在法律上没有任何意义(并且可能不正确或没有先例支持,我不是律师),但可能足以让您开始与您的法律人对话。
从参考页面:
简单地将受版权保护的作品与另一件作品结合并不会产生衍生作品。必须以某种方式修改原始版权作品。由此产生的衍生作品本身必须“代表原创作品”。因此,如果被许可人不修改原始的 GPL 许可程序,而只是运行它,那么他并不是在创作衍生作品。
还有就是Appassembler Maven插件,我认为做什么,你需要(尽管它创造JSW包装)。它创建一个 shell 脚本(和一个 bat 文件),并将所有应用程序 jar 收集到一个目录中。可以选择将其配置为创建基于 JSW 的守护程序配置。
下面是一个示例配置,它将在 target/appassembler 文件夹中生成独立应用程序,并在 target/appassembler/jsw/myApp 目录中生成 JSW 包装文件。注意 assemble 目标绑定到集成测试阶段以确保创建项目的 jar。要生成输出,请运行mvn verify或仅生成服务包装器运行mvn package:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>assemble-standalone</id>
<phase>integration-test</phase>
<goals>
<goal>assemble</goal>
</goals>
<configuration>
<programs>
<program>
<mainClass>name.seller.rich.MyMainClass</mainClass>
<name>myShellScript</name>
</program>
</programs>
<platforms>
<platform>windows</platform>
<platform>unix</platform>
</platforms>
<!--collect all jars into the lib directory-->
<repositoryLayout>flat</repositoryLayout>
<repositoryName>lib</repositoryName>
</configuration>
</execution>
<execution>
<id>generate-jsw-scripts</id>
<phase>package</phase>
<goals>
<goal>generate-daemons</goal>
</goals>
<configuration>
<!--declare the JSW config -->
<daemons>
<daemon>
<id>myApp</id>
<mainClass>name.seller.rich.MyMainClass</mainClass>
<commandLineArguments>
<commandLineArgument>start</commandLineArgument>
</commandLineArguments>
<platforms>
<platform>jsw</platform>
</platforms>
</daemon>
</daemons>
<target>${project.build.directory}/appassembler</target>
</configuration>
</execution>
</executions>
</plugin>
生成的文件如下,供参考:
myApp\bin\myApp
myApp\bin\myApp.bat
myApp\bin\wrapper-linux-x86-32
myApp\bin\wrapper-macosx-universal-32
myApp\bin\wrapper-solaris-x86-32
myApp\bin\wrapper-windows-x86-32.exe
myApp\conf\wrapper.conf
myApp\lib\libwrapper-linux-x86-32.so
myApp\lib\libwrapper-macosx-universal-32.jnilib
myApp\lib\libwrapper-solaris-x86-32.so
myApp\lib\wrapper-windows-x86-32.dll
myApp\lib\wrapper.jar
IT小君
Linux 上的服务只是启动后台进程的 shell 脚本。看看
/etc/init.d- 您可以在文本编辑器中打开文件。所有你需要的是一个bash脚本,响应参数start并stop以适当的方式(例如,start将启动您的服务,并在已知位置记录进程ID,stop将杀死的PID从创建该文件的进程),然后把它放在/etc/init.d.查看初始化脚本和服务、运行级别和 rc.d 脚本简介