我开发了一个收集一些数据的桌面应用程序(客户端)。即使没有互联网连接也能正常工作。
我想在java中创建一个Windows服务,每次建立Internet连接时,都会从apps数据库中获取数据并将其发送到某个远程服务器。
我一直在网上搜索如何以及如何用java创建Windows服务,我得到的是
Java Service Wrapper
互联网上的人们似乎都在使用它,但对我来说,我还没能找到一个合适的文档来说明我如何创建服务。
任何人都可以帮助我创建一个Windows服务或类似的东西。
答案 0 :(得分:1)
添加类似于你的pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>generate-jsw-scripts</id>
<phase>package</phase>
<goals>
<goal>generate-daemons</goal>
</goals>
<configuration>
<repositoryLayout>flat</repositoryLayout>
<includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
<daemons>
<daemon>
<id>${jsw_name}</id>
<mainClass>${path_to_runner_class}</mainClass>
<commandLineArguments>
<commandLineArgument>start</commandLineArgument>
</commandLineArguments>
<jvmSettings>
<initialMemorySize>512M</initialMemorySize>
<maxMemorySize>512M</maxMemorySize>
<!--systemProperties><systemProperty>com.sun.management.jmxremote</systemProperty><systemProperty>com.sun.management.jmxremote.port=9010</systemProperty><systemProperty>com.sun.management.jmxremote.local.only=false</systemProperty><systemProperty>com.sun.management.jmxremote.authenticate=false</systemProperty><systemProperty>com.sun.management.jmxremote.ssl=false</systemProperty><systemProperty>org.tanukisoftware.wrapper.WrapperManager.mbean=TRUE</systemProperty><systemProperty>org.tanukisoftware.wrapper.WrapperManager.mbean.testing=false</systemProperty></systemProperties-->
</jvmSettings>
<generatorConfigurations>
<generatorConfiguration>
<generator>jsw</generator>
<includes>
<include>linux-x86-64</include>
<include>windows-x86-64</include>
</includes>
</generatorConfiguration>
</generatorConfigurations>
<platforms>
<platform>jsw</platform>
</platforms>
</daemon>
</daemons>
</configuration>
</execution>
</executions>
</plugin>
输入名称而不是jsw_name,例如jsw_example和你的跑步者类的路径(具有主要功能的类),例如com.copper.drivers.emulation.Runner而不是path_to_runner_class。 然后构建项目。转到target \ generated-resources \ appassembler \ jsw \ $ {project_name} \ bin \,在那里你会发现从windows和linux运行的文件。 以管理员身份打开cmd并使用命令运行它们: $ {project_name}控制台 - 如果你想在控制台中运行它 $ {project_name} start - 将其作为服务运行。
如果需要jmx取消注释systemProperties。
P.S。 如果您使用linux - 使用命令bin / $ {project_name} start或bin / $ {project_name} console从$ {project_name}目录启动它。