13
13
* limitations under the License.
14
14
*/
15
15
16
- import org . mortbay . jetty . Connector ;
16
+ import java . io . File
17
17
import org .mortbay .jetty .Server ;
18
18
import org .mortbay .jetty .bio .SocketConnector ;
19
19
import org .mortbay .jetty .webapp .WebAppContext ;
@@ -32,9 +32,9 @@ object JettyStarter {
32
32
val bb = new WebAppContext ();
33
33
bb.setServer(server);
34
34
bb.setContextPath(" /" );
35
- bb.setWar(" submitit-webapp/src/main/webapp " );
35
+ bb.setWar(webappDir.toString );
36
36
37
- System .setProperty(" submitit.properties" , " submitit-webapp/ src/main/resources/submitit.properties" )
37
+ System .setProperty(" submitit.properties" , new File (getBaseDir(getClass), " src/main/resources/submitit.properties" ).toString )
38
38
39
39
server.addHandler(bb);
40
40
@@ -53,4 +53,31 @@ object JettyStarter {
53
53
}
54
54
}
55
55
}
56
+
57
+ private def webappDir : File = {
58
+ val dir = new File (getBaseDir(getClass), " src/main/webapp" )
59
+ if (! dir.exists()) {
60
+ throw new RuntimeException (" Unable to find web application directory" )
61
+ }
62
+ dir
63
+ }
64
+
65
+ private def getBaseDir (c : Class [_]): File = {
66
+ val basedir = System .getProperty(" basedir" );
67
+ if (basedir != null ) {
68
+ new File (basedir)
69
+ } else {
70
+ var file = new File (c.getProtectionDomain.getCodeSource.getLocation.getPath)
71
+ if (! file.exists()) {
72
+ throw new RuntimeException (" Unable to find basedir" )
73
+ }
74
+ while (! new File (file, " pom.xml" ).exists()) {
75
+ file = file.getParentFile
76
+ if (file == null ) {
77
+ throw new RuntimeException (" Unable to find basedir" )
78
+ }
79
+ }
80
+ file;
81
+ }
82
+ }
56
83
}
0 commit comments