Skip to content

Commit 01d31d8

Browse files
author
unknown
committedJan 4, 2012
yajsw + jamod
1 parent d2cd56d commit 01d31d8

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package modbus.control;
2+
3+
import java.io.File;
4+
import org.eclipse.jetty.server.Server;
5+
import org.eclipse.jetty.util.thread.QueuedThreadPool;
6+
import org.eclipse.jetty.webapp.WebAppContext;
7+
import org.tanukisoftware.wrapper.WrapperListener;
8+
import org.tanukisoftware.wrapper.WrapperManager;
9+
10+
public class EmbeddedJettyService implements WrapperListener {
11+
12+
@Override
13+
public Integer start(String[] arg0) {
14+
try {
15+
// Create an embedded Jetty server on port 8080
16+
Server server = new Server(8080);
17+
18+
// Create a handler for processing our GWT app
19+
WebAppContext handler = new WebAppContext();
20+
handler.setContextPath("/");
21+
22+
String prjFolder = System.getProperty("user.dir") + "\\..\\modctrl-webapp\\target";
23+
24+
File warFile = new File(prjFolder.toString());
25+
File[] listFiles = warFile.listFiles();
26+
for (File file : listFiles) {
27+
if (file.isFile() && file.getName().endsWith(".war")) {
28+
handler.setWar(file.getAbsolutePath());
29+
}
30+
}
31+
32+
if (handler.getWar() == null || handler.getWar().isEmpty()) {
33+
prjFolder = System.getProperty("user.dir") + "\\..\\lib";
34+
35+
warFile = new File(prjFolder.toString());
36+
listFiles = warFile.listFiles();
37+
for (File file : listFiles) {
38+
if (file.isFile() && file.getName().endsWith(".war")) {
39+
handler.setWar(file.getAbsolutePath());
40+
}
41+
}
42+
}
43+
44+
// Add it to the server
45+
server.setHandler(handler);
46+
47+
// Other misc. options
48+
server.setThreadPool(new QueuedThreadPool(20));
49+
50+
// And start it up
51+
server.start();
52+
server.join();
53+
54+
return 0;
55+
} catch (Exception e) {
56+
System.out.println(e.getMessage());
57+
}
58+
59+
return 0;
60+
}
61+
62+
@Override
63+
public int stop(int exitCode) {
64+
65+
return 0;
66+
}
67+
68+
@Override
69+
public void controlEvent(int event) {
70+
if (WrapperManager.isControlledByNativeWrapper()) {
71+
// The Wrapper will take care of this event
72+
} else {
73+
// We are not being controlled by the Wrapper, so
74+
// handle the event ourselves.
75+
if ((event == WrapperManager.WRAPPER_CTRL_C_EVENT) || (event == WrapperManager.WRAPPER_CTRL_CLOSE_EVENT)
76+
|| (event == WrapperManager.WRAPPER_CTRL_SHUTDOWN_EVENT)) {
77+
WrapperManager.stop(0);
78+
}
79+
}
80+
}
81+
82+
/*---------------------------------------------------------------
83+
* Main Method
84+
*-------------------------------------------------------------*/
85+
public static void main(String[] args) {
86+
// Start the application. If the JVM was launched from the native
87+
// Wrapper then the application will wait for the native Wrapper to
88+
// call the application's start method. Otherwise the start method
89+
// will be called immediately.
90+
WrapperManager.start(new EmbeddedJettyService(), args);
91+
}
92+
}

0 commit comments

Comments
 (0)
Please sign in to comment.