11
11
package modbus .control .service ;
12
12
13
13
import java .io .File ;
14
+ import java .util .ArrayList ;
15
+ import java .util .Collections ;
16
+ import java .util .HashMap ;
17
+ import java .util .List ;
18
+ import java .util .Map ;
14
19
import java .util .concurrent .ExecutorService ;
15
20
import java .util .concurrent .Executors ;
16
21
import java .util .concurrent .Future ;
17
22
import java .util .concurrent .TimeUnit ;
18
23
19
24
import jnacontrib .win32 .Win32Service ;
20
25
26
+ import org .apache .log4j .Logger ;
21
27
import org .rzo .yajsw .boot .WrapperLoader ;
22
- import org .rzo .yajsw .config .YajswConfiguration ;
23
- import org .rzo .yajsw .config .YajswConfigurationImpl ;
24
28
import org .rzo .yajsw .os .OperatingSystem ;
25
29
import org .rzo .yajsw .os .StopableService ;
26
30
import org .rzo .yajsw .wrapper .WrappedProcess ;
@@ -40,6 +44,7 @@ public class WrapperMainServiceWin extends Win32Service implements StopableServi
40
44
/** The service. */
41
45
static WrapperMainServiceWin service ;
42
46
static ExecutorService pool = Executors .newFixedThreadPool (5 );
47
+ private static final Logger logger = Logger .getLogger (WrapperMainServiceWin .class );
43
48
44
49
/**
45
50
* Instantiates a new wrapper main service.
@@ -56,16 +61,23 @@ public WrapperMainServiceWin() {
56
61
*/
57
62
public static void main (String [] args ) {
58
63
System .setProperty ("wrapper.config" , System .getProperty ("user.dir" ) + "\\ src\\ main\\ resources\\ wrapper.conf" );
59
-
64
+ System .setProperty ("wrapper.java.app.mainclass" , "modbus.control.EmbeddedJetty" ); // system properties overwrite properties in conf file.
65
+ System .setProperty ("wrapper.tray" , "false" );
66
+
60
67
String wrapperJar = WrapperLoader .getWrapperJar ();
61
68
// set home dir of the service to the wrapper jar parent, so that we may find required libs
62
69
String homeDir = new File (wrapperJar ).getParent ();
63
- OperatingSystem .instance ().setWorkingDir (System .getProperty ("user.dir" ) + "\\ target\\ dependency" );
64
- YajswConfigurationImpl _config = new YajswConfigurationImpl (true );
65
-
70
+ OperatingSystem .instance ().setWorkingDir (System .getProperty ("user.dir" ));
71
+
66
72
service = new WrapperMainServiceWin ();
73
+
74
+
75
+ if (false ) {
76
+ service .install ("Modbus Control" , "control modbus PLC" , null , "ares" , "Jas1MinB" , true );
77
+ return ;
78
+ }
79
+
67
80
// set service shutdown timeout
68
- service .setServiceName (_config .getString ("wrapper.ntservice.name" ));
69
81
// int timeout = _config.getInt("wrapper.shutdown.timeout", Constants.DEFAULT_SHUTDOWN_TIMEOUT) * 1000;
70
82
// timeout += _config.getInt("wrapper.script.STOP.timeout", 0) * 1000;
71
83
// timeout += _config.getInt("wrapper.script.SHUTDOWN.timeout", 0) * 1000;
@@ -75,26 +87,11 @@ public static void main(String[] args) {
75
87
//
76
88
// timeout = _config.getInt("wrapper.startup.timeout", Constants.DEFAULT_STARTUP_TIMEOUT) * 1000;
77
89
service .setStartupTimeout (3000 );
78
- //
79
- // service.setAutoReportStartup(_config.getBoolean("wrapper.ntservice.autoreport.startup", true));
80
- //
81
- // if (_config.containsKey("wrapperx.config"))
82
- // {
83
- // List<String> configs = _config.getList("wrapperx.config");
84
- // wList = WrappedProcessFactory.createProcessList(new HashMap(), configs, true);
85
- // for (WrappedProcess p : wList)
86
- // {
87
- // p.setService(service);
88
- // }
89
- // }
90
- // else
91
- // {
92
90
93
- // global configuration
91
+ Map configuration = new HashMap ();
92
+ WrappedProcess wp = (WrappedProcess ) WrappedProcessFactory .createProcess (configuration , true );
93
+
94
94
95
- WrappedProcess wp = WrappedProcessFactory .createProcess ((YajswConfiguration )_config );
96
-
97
-
98
95
// set service in wrapper so that we may stop the service in case the application terminates and we need to shutdown the wrapper
99
96
wp .setService (service );
100
97
wp .init ();
@@ -148,6 +145,29 @@ public void run() {
148
145
Runtime .getRuntime ().halt (0 );
149
146
}
150
147
148
+ @ Override
149
+ public boolean install (String displayName , String description , String [] dependencies , String account , String password , boolean delayedAutostart ) {
150
+ File prjFolder = new File (System .getProperty ("user.dir" ) + "\\ target\\ dependency" );
151
+ if (!prjFolder .exists ()) {
152
+ prjFolder = new File (System .getProperty ("user.dir" ) + "\\ ..\\ lib" );
153
+ if (!prjFolder .exists ()) {
154
+ logger .error ("NO LIBRARYS FOUND" );
155
+ return false ;
156
+ }
157
+ }
158
+
159
+ List <String > depFiles = new ArrayList <String >();
160
+ for (File dependencyFile : prjFolder .listFiles ()) {
161
+
162
+ if (dependencyFile .isFile () && dependencyFile .getName ().endsWith ("jar" )) {
163
+ depFiles .add (dependencyFile .getAbsolutePath ());
164
+ }
165
+ }
166
+ dependencies = depFiles .toArray (new String [0 ]);
167
+
168
+ return super .install (displayName , description , dependencies , account , password , delayedAutostart );
169
+ }
170
+
151
171
/*
152
172
* (non-Javadoc)
153
173
*
0 commit comments