1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.maven.plugin;
20
21 import java.io.File;
22 import java.util.List;
23
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.maven.plugin.MojoFailureException;
26 import org.eclipse.jetty.util.PathWatcher;
27 import org.eclipse.jetty.util.PathWatcher.PathWatchEvent;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 public class JettyRunWarMojo extends AbstractJettyMojo
49 {
50
51
52
53
54
55
56 private File war;
57
58
59
60
61
62 public void execute() throws MojoExecutionException, MojoFailureException
63 {
64 super.execute();
65 }
66
67
68 @Override
69 public void finishConfigurationBeforeStart() throws Exception
70 {
71 server.setStopAtShutdown(true);
72 super.finishConfigurationBeforeStart();
73 }
74
75
76
77 public void configureWebApplication () throws Exception
78 {
79 super.configureWebApplication();
80
81 webApp.setWar(war.getCanonicalPath());
82 }
83
84
85
86
87
88
89
90 public void checkPomConfiguration() throws MojoExecutionException
91 {
92 return;
93 }
94
95
96
97
98
99
100
101 public void configureScanner() throws MojoExecutionException
102 {
103 scanner.watch(project.getFile().toPath());
104 scanner.watch(war.toPath());
105
106 scanner.addListener(new PathWatcher.EventListListener()
107 {
108
109 @Override
110 public void onPathWatchEvents(List<PathWatchEvent> events)
111 {
112 try
113 {
114 boolean reconfigure = false;
115 for (PathWatchEvent e:events)
116 {
117 if (e.getPath().equals(project.getFile().toPath()))
118 {
119 reconfigure = true;
120 break;
121 }
122 }
123 restartWebApp(reconfigure);
124 }
125 catch (Exception e)
126 {
127 getLog().error("Error reconfiguring/restarting webapp after change in watched files",e);
128 }
129 }
130 });
131 }
132
133
134
135
136
137
138
139 public void restartWebApp(boolean reconfigureScanner) throws Exception
140 {
141 getLog().info("Restarting webapp ...");
142 getLog().debug("Stopping webapp ...");
143 stopScanner();
144 webApp.stop();
145 getLog().debug("Reconfiguring webapp ...");
146
147 checkPomConfiguration();
148
149
150
151 if (reconfigureScanner)
152 {
153 getLog().info("Reconfiguring scanner after change to pom.xml ...");
154 scanner.reset();
155 configureScanner();
156 }
157
158 getLog().debug("Restarting webapp ...");
159 webApp.start();
160 startScanner();
161 getLog().info("Restart completed.");
162 }
163
164 }