.net和jar包windows服务部署

一.NetCore

1.创建启动脚本run_instal.bat,例如程序文件为ApiDoc.exe

复制代码
set serviceName="Apidoc Web 01"
set serviceFilePath=%~dp0ApiDoc.exe
set serviceDescription="ApiDoc 动态接口服务 web 01"

sc create %serviceName%  BinPath=%serviceFilePath%
sc config %serviceName%  start=auto  
sc description %serviceName%  %serviceDescription%
sc start  %serviceName%
pause

serviceName 服务名,如果多个单子可以有空格,但必须用""包起立

description 服务说明 BinPath 路径

%~dp0 当前bat文件路径 start=auto 开机自动启动 start: 启动服务

2.卸载脚本run_unstall.bat

复制代码
set serviceName="Apidoc Web 01"

sc stop %serviceName% 
sc delete %serviceName% 

pause

windows服务只能以命令方式卸载,最后把bat文件和.exe文件放在同目录下

二.普通jar包

1.下载WinSW,根据服务器的.net环境自行选择,此处使用WinSW-x64.exe

复制代码
https://github.com/winsw/winsw/releases
https://github.com/winsw/winsw/tree/v2.12.0?tab=readme-ov-file

2.将WinSW-x64.exe重命名为WinServerTest.exe,并拷贝到jar包同目录

3.新建一个WinServerTest.xml的文件,编码格式为UTF-8,内容如下

复制代码
<service>
  
  <!-- ID of the service. It should be unique across the Windows system-->
  <id>WinServerTest</id>
  
  <!-- 服务名 -->
  <name>WinServerTest</name>
  
  <!-- 服务说明 -->
  <description>This service is a service test WinServerTest</description>
  
  <!-- 应启动的可执行文件的路径 -->
  <executable>java</executable>
  
  <!-- 当前路径的程序 -->
  <arguments>-jar WinServerTest-1.jar</arguments> 
  
  <!-- 服务启动模式 Automatic:自动 -->
  <startmode>Automatic</startmode>
  
  <!-- 日志位置,为当前路径logs文件夹下 -->
  <logpath>logs</logpath>
  
</service>

4.创建安装服务脚本install.bat

复制代码
cd %~dp0
WinServerTest install
WinServerTest start
pause

5.创建删除服务脚本uninstall.bat

复制代码
cd %~dp0
WinServerTest stop
WinServerTest uninstall
pause

6.最后的文件目录

三.

相关推荐
Beyond_System|系统之外1 分钟前
Windows 10/11 安装与配置 Zig 0.13.0:从下载到编译验证的完整教程
windows·编译工具
2601_962381581 小时前
Mac和Windows,哪种电脑适合新手学Python|数智码力分享
windows·python·mac·编程环境·学习入门
会飞的拖把2 小时前
Python序列详解:列表、元组、字符串的通用操作(超详细版)
开发语言·windows·python
阿沐沐,4 小时前
Claude Code 安装教程:Windows、WSL 2 与 macOS
windows·macos
水饺编程4 小时前
编程数学:三角函数基础01,直角三角函数
c语言·c++·windows·visual studio
kaixin_啊啊4 小时前
PandaWiki 本地 AI 知识库实战:文档导入、智能问答与远程访问
linux·服务器·人工智能·windows·ai
檀越剑指大厂5 小时前
OpenClaw 实测:Windows 安装、模型配置、电脑任务执行与公网访问
windows
西西弗Sisyphus5 小时前
Qt 实现一个 Windows 启动项查看器
开发语言·windows·qt
嘿嘿-6617 小时前
Windows 一键使用 GPT-6 Astra:Codex CLI 配置教程
java·人工智能·windows·gpt·chatgpt·web
郝学胜-神的一滴18 小时前
Qt 高级编程 045:坐标体系深度实战
开发语言·c++·windows·python·qt·程序人生