1.首先把jdk 数据库等项目运行环境在服务器上搭建起来
2. 部署项目需要4个文件 如下图
3.添加 xxx.bat 文件 , 这个文件用于在服务器服务中新增一个服务 , 文件内容
下面代码中需要修改的内容:
sc create 新增的服务名称 binPath= xxx.exe文件的路径 start= auto
@echo off
echo try get Administrator
cacls.exe "%SystemDrive%\System Volume Information" >nul 2>nul
if %errorlevel%==0 goto Admin
if exist "%temp%\getadmin.vbs" del /f /q "%temp%\getadmin.vbs"
echo Set RequestUAC = CreateObject^("Shell.Application"^)>"%temp%\getadmin.vbs"
echo RequestUAC.ShellExecute "%~s0","","","runas",1 >>"%temp%\getadmin.vbs"
echo WScript.Quit >>"%temp%\getadmin.vbs"
"%temp%\getadmin.vbs" /f
if exist "%temp%\getadmin.vbs" del /f /q "%temp%\getadmin.vbs"
exit
:Admin
echo get Administrator success
sc create hardwaretransferService binPath= E:\counter\hardwaretransfer\hardwaretransferService.exe start= auto
pause
4.添加xxx.exe文件
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
[assembly: AssemblyCopyright("Copyright 2008-2016 Oleg Nenashev, CloudBees, Inc. and other contributors")]
[assembly: AssemblyTitle("Windows Service Wrapper for .NET4")]
[assembly: AssemblyDescription("Allows arbitrary process to run as a Windows service by wrapping it")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("CloudBees, Inc.")]
[assembly: AssemblyProduct("Windows Service Wrapper")]
[assembly: TargetFramework(".NETFramework,Version=v4.0", FrameworkDisplayName = ".NET Framework 4")]
[assembly: AssemblyTrademark("")]
[assembly: Guid("59ce18df-cacb-4360-bb80-798bd6459ca3")]
[assembly: AssemblyFileVersion("2.2.0")]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: ComVisible(false)]
[assembly: AssemblyDelaySign(true)]
[assembly: SecurityPermission(8, SkipVerification = true)]
[assembly: AssemblyVersion("2.2.0.0")]
[module: UnverifiableCode]
5.添加xxx.xml
<configuration>
<!-- ID of the service. It should be unique accross the Windows system-->
<id>项目名</id>
<!-- Display name of the service -->
<name>项目名</name>
<!-- Service description -->
<description>项目描述</description>
<!-- Path to the executable, which should be started -->
<executable>java</executable>
<arguments>-jar xxx.jar</arguments>
<serviceaccount>
<user>LocalSystem</user>
</serviceaccount>
<logpath>%BASE%\logs</logpath>
<log mode="roll-by-time">
<pattern>yyyyMMdd</pattern>
</log>
</configuration>
- 把项目package出来 --> xxx.jar
- 双击运行xxx.bat 文件 等待出现 按任意键继续 退出 , 在电脑服务中找到新增的服务 , 点击左侧启动 , 一般项目启动是会有日志生成 , 可以在日志中看一下 服务是不是正常启动了
版权声明:本文为weixin_44244206原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。