1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.embedded;
20
21 import java.io.File;
22
23 import org.eclipse.jetty.plus.jndi.EnvEntry;
24 import org.eclipse.jetty.plus.jndi.Resource;
25 import org.eclipse.jetty.plus.jndi.Transaction;
26 import org.eclipse.jetty.security.HashLoginService;
27 import org.eclipse.jetty.server.Server;
28 import org.eclipse.jetty.webapp.Configuration;
29 import org.eclipse.jetty.webapp.WebAppContext;
30
31
32
33
34 public class ServerWithAnnotations
35 {
36 public static final void main( String args[] ) throws Exception
37 {
38
39 Server server = new Server(8080);
40
41
42 Configuration.ClassList classlist = Configuration.ClassList
43 .setServerDefault(server);
44 classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration",
45 "org.eclipse.jetty.plus.webapp.EnvConfiguration",
46 "org.eclipse.jetty.plus.webapp.PlusConfiguration");
47 classlist.addBefore(
48 "org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
49 "org.eclipse.jetty.annotations.AnnotationConfiguration");
50
51
52 WebAppContext webapp = new WebAppContext();
53 webapp.setContextPath("/");
54 File warFile = new File(
55 "../../jetty-distribution/target/distribution/demo-base/webapps/test.war");
56 webapp.setWar(warFile.getAbsolutePath());
57 webapp.setAttribute(
58 "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
59 ".*/javax.servlet-[^/]*\\.jar$|.*/servlet-api-[^/]*\\.jar$");
60 server.setHandler(webapp);
61
62
63
64 new Transaction(new com.acme.MockUserTransaction());
65
66
67 new EnvEntry(webapp, "maxAmount", new Double(100), true);
68
69
70 new Resource(webapp, "jdbc/mydatasource", new com.acme.MockDataSource());
71
72
73 HashLoginService loginService = new HashLoginService();
74 loginService.setName("Test Realm");
75 loginService.setConfig("src/test/resources/realm.properties");
76 server.addBean(loginService);
77
78 server.start();
79 server.join();
80 }
81
82 }