|
1 package ru.indvdum.mywork; |
|
2 |
|
3 import java.util.Date; |
|
4 |
|
5 import javax.persistence.EntityManager; |
|
6 import javax.persistence.EntityManagerFactory; |
|
7 import javax.persistence.Persistence; |
|
8 |
|
9 import org.mortbay.component.LifeCycle; |
|
10 import org.mortbay.component.LifeCycle.Listener; |
|
11 import org.mortbay.jetty.Connector; |
|
12 import org.mortbay.jetty.Server; |
|
13 import org.mortbay.jetty.servlet.Context; |
|
14 import org.mortbay.jetty.servlet.ServletHolder; |
|
15 |
|
16 import com.vaadin.terminal.gwt.server.ApplicationServlet; |
|
17 |
|
18 /** |
|
19 * @author indvdum |
|
20 * 12.08.2011 17:31:37 |
|
21 * |
|
22 */ |
|
23 public class MyWork { |
|
24 public static EntityManagerFactory EMF = null; |
|
25 public static EntityManager EM = null; |
|
26 |
|
27 /** |
|
28 * @param args |
|
29 * @throws Exception |
|
30 */ |
|
31 public static void main(String[] args) throws Exception { |
|
32 Server server = new Server(); |
|
33 Connector connector = new org.mortbay.jetty.nio.SelectChannelConnector(); |
|
34 connector.setPort(8080); |
|
35 connector.setMaxIdleTime(720000); |
|
36 server.addConnector(connector); |
|
37 |
|
38 Context root = new Context(server, "/", Context.SESSIONS); |
|
39 ServletHolder vaadinServlet = new ServletHolder(new ApplicationServlet()); |
|
40 vaadinServlet.setInitParameter("application", "ru.indvdum.mywork.vaadin.MyWorkApplication"); |
|
41 root.addServlet(vaadinServlet, "/*"); |
|
42 |
|
43 server.addLifeCycleListener(new Listener(){ |
|
44 |
|
45 @Override |
|
46 public void lifeCycleFailure(LifeCycle event, Throwable cause) { |
|
47 |
|
48 } |
|
49 |
|
50 @Override |
|
51 public void lifeCycleStarted(LifeCycle event) { |
|
52 EMF = Persistence.createEntityManagerFactory("mywork"); |
|
53 EM = EMF.createEntityManager(); |
|
54 } |
|
55 |
|
56 @Override |
|
57 public void lifeCycleStarting(LifeCycle event) { |
|
58 |
|
59 } |
|
60 |
|
61 @Override |
|
62 public void lifeCycleStopped(LifeCycle event) { |
|
63 |
|
64 } |
|
65 |
|
66 @Override |
|
67 public void lifeCycleStopping(LifeCycle event) { |
|
68 EM.close(); |
|
69 EMF.close(); |
|
70 } |
|
71 |
|
72 }); |
|
73 |
|
74 server.start(); |
|
75 System.out.println("Jetty server started at " + new Date()); |
|
76 } |
|
77 |
|
78 } |