windows服务器上部署Java项目

1.首先把jdk 数据库等项目运行环境在服务器上搭建起来
2. 部署项目需要4个文件 如下图
windows服务器上部署Java项目_第1张图片
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>项目名id>
  
  <name>项目名name>
  
  <description>项目描述description>
  
  
  <executable>javaexecutable>
  <arguments>-jar xxx.jararguments>

	<serviceaccount>
	  <user>LocalSystemuser>
	serviceaccount>

  <logpath>%BASE%\logslogpath>
  <log mode="roll-by-time">
	<pattern>yyyyMMddpattern>
 log>
configuration>
  1. 把项目package出来 --> xxx.jar
  2. 双击运行xxx.bat 文件 等待出现 按任意键继续 退出 , 在电脑服务中找到新增的服务 , 点击左侧启动 , 一般项目启动是会有日志生成 , 可以在日志中看一下 服务是不是正常启动了

你可能感兴趣的:(windows,服务器,java)