maven javaProject打包發佈成服務

1,如今pom.xml中添加打包所須要的jar包。java

 1 <plugins>
 2 <plugin>  
 3     <groupId>org.apache.maven.plugins</groupId>  
 4     <artifactId>maven-shade-plugin</artifactId>  
 5     <version> 1.7.1</version>  
 6     <configuration>
 7         <createDependencyReducedPom>false</createDependencyReducedPom>
 8     </configuration>
 9     <executions>  
10         <execution>  
11             <phase>package</phase>  
12             <goals>  
13                 <goal>shade</goal>  
14             </goals>  
15             <configuration>  
16                 <transformers>  
17                      <transformer  
18                         implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">  
19                         <resource>META-INF/spring.handlers</resource>  
20                     </transformer>  
21                     <transformer  
22                         implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">  
23                         <resource>META-INF/spring.schemas</resource>  
24                     </transformer>  
25                     <transformer  
26                         implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">  
27                         <mainClass>com.dsdl.server.Main</mainClass>  
28                     </transformer>  
29                 </transformers>  
30             </configuration>  
31         </execution>  
32     </executions>  
33 </plugin>
34 </plugins>    

2,右擊項目 選擇-->run --->run configurations -->maven build ,右擊maven build ---> Newweb

 

選擇Browse Workspace 選中要發佈的javaprojectspring

Goals: clean packageapache

Maven Runtime :選中Maven的安裝路徑。服務器

最後點擊 Run,在項目的target文件夾下面會出現這些文件。其中標出的那個是須要拷到服務器上的。app

 

3,拷到服務器上。放到磁盤的文件夾下。另外要寫個批處理 reg.bat 和運行環境 javaService.exe。jvm

reg 的內容:maven

  1 @echo off  
  2   
  3 rem 修改控制檯顏色  
  4 color 1d  
  5   
  6 rem * 使用JavaService將TestTimer安裝爲Windows服務的腳本  
  7 rem *  
  8 rem * JavaService - Windows NT Service Daemon for Java applications  
  9 rem * Copyright (C) 2006 Multiplan Consultants Ltd. LGPL Licensing applies  
 10 rem * Information about the JavaService software is available at the ObjectWeb  
 11 rem * web site. Refer to http://javaservice.objectweb.org for more details.  
 12   
 13 rem 開始批處理文件中環境改動的本地化操做,在使用endlocal後環境將恢復到原先的內容  
 14 SETLOCAL  
 15   
 16 rem 設置環境變量,指向當前路徑  
 17 SET BASE_PATH=%CD%
 18 rem 設置Java path: jre_home  
 19 SET JRE_HOME=C:\Program Files\Java\jre7
 20 rem 判斷JRE_HOME是否正確 
 21 if "%JRE_HOME%" == "" goto no_java  
 22 if not exist "%JRE_HOME%\bin\java.exe" goto no_java
 23 rem 設置jvm內存分配狀況  
 24 set JVM_MEMORY=-Xms256m -Xmx512m   
 25   
 26 rem 設置jvmdll使用哪種模式  
 27 SET jvmdll=%JRE_HOME%\bin\client\jvm.dll
 28 if not exist "%jvmdll%" SET jvmdll=%JRE_HOME%\bin\server\jvm.dll  
 29 if not exist "%jvmdll%" goto no_java  
 30   
 31 rem 設置JavaService路徑  
 32 set JSBINDIR=E:\project
 33 set JSEXE=%JSBINDIR%\JavaService.exe  
 34   
 35 rem 判斷jar是否正確  
 36 SET acctjar=%BASE_PATH%\UDPServer-0.0.1-SNAPSHOT.jar
 37 if not exist "%acctjar%" goto no_peer  
 38   
 39 @echo . Using following version of JavaService executable:  
 40 @echo .  
 41 "%JSEXE%" -version  
 42 @echo .  
 43   
 44 rem parameters and files seem ok, go ahead with the service installation  
 45 @echo .  %BASE_PATH% +++++++++++++++++++
 46   
 47 rem 處理該批處理的輸入參數,後臺服務啓動模式:自動  
 48 SET svcmode=
 49 if "%1" == "-manual" SET svcmode=-manual
 50 if "%1" == "-auto" SET svcmode=-auto  
 51   
 52   
 53 rem 設置JAVA_OPTS  
 54 set JAVA_OPTS=%JAVA_OPTS% -Djava.class.path="%BASE_PATH%\UDPServer-0.0.1-SNAPSHOT.jar"  
 55 set JAVA_OPTS=%JAVA_OPTS% %JVM_MEMORY%  
 56   
 57 rem 設置startstop  
 58 SET START_STOP=-start com.dsdl.server.Main 
 59   
 60   
 61 rem 設置Log文件路徑  
 62 set OUT_ERR=-out "%BASE_PATH%\service_out.log" -err "%BASE_PATH%\service_err.log"  
 63   
 64 rem 設置desp  
 65 set DESP=-description "UdpServer Service"   
 66   
 67 rem 設置執行命令行  
 68 set runcmd="%JSEXE%" -install UDPSERVER  
 69 set runcmd=%runcmd% "%jvmdll%"  
 70 set runcmd=%runcmd% %JAVA_OPTS%  
 71 set runcmd=%runcmd% %START_STOP%  
 72 set runcmd=%runcmd% %OUT_ERR%  
 73 set runcmd=%runcmd% -current  
 74 set runcmd=%runcmd% "%BASE_PATH%"  
 75 set runcmd=%runcmd% %svcmode%  
 76 set runcmd=%runcmd% -overwrite  
 77 set runcmd=%runcmd% -startup 6  
 78 set runcmd=%runcmd% %DESP%  
 79 echo %runcmd%  
 80   
 81 rem 執行安裝命令  
 82 %runcmd%  
 83   
 84 rem 啓動服務  
 85 net start UDPSERVER
 86 if ERRORLEVEL 1 goto js_error  
 87   
 88 goto end  
 89   
 90 :no_java  
 91 @echo . No java Evn  
 92 goto error_exit  
 93   
 94 :no_peer  
 95 @echo . jar is not exist  
 96 goto error_exit  
 97   
 98   
 99 :no_jsexe  
100 @echo . JavaService.exe is not exist 
101 goto error_exit  
102   
103   
104 :js_error  
105 @echo . UDPSERVER error
106 goto error_exit  
107   
108 :error_exit  
109   
110 @echo .  
111 @echo . install fail,can not make UDPServer-0.0.1-SNAPSHOT install for Windows Service 
112 @echo .  
113 @echo . mingling geshi:  
114 @echo .  
115 @echo .  %~n0 [-auto / -manual] [-np]  
116 @echo .  
117 @echo . qizhong:  
118 @echo .  -auto (默認) or -manual 參數說明了服務的啓動模式:自動或者手動  
119 @echo .  -np 批處理命令執行完畢後不暫停  
120 @echo .  
121 @echo . 好比:  
122 @echo .  %~n0 -auto -np  
123   
124 :end  
125 ENDLOCAL  
126 @echo .  
127 if "%2" NEQ "-np" @pause  

4,最後雙擊 reg.bat 便可。ui

提示:必須有權限的登陸帳號才註冊服務。開始我本身的帳號,怎麼試都不行,後來改爲administrator帳號,才成功。spa

相關文章
相關標籤/搜索