Skip to content
This repository was archived by the owner on Sep 28, 2023. It is now read-only.

Commit b16b625

Browse files
committed
jetty starter now looks up the path correctly
1 parent 21170c7 commit b16b625

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

submitit-webapp/src/test/scala/JettyStarter.scala

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16-
import org.mortbay.jetty.Connector;
16+
import java.io.File
1717
import org.mortbay.jetty.Server;
1818
import org.mortbay.jetty.bio.SocketConnector;
1919
import org.mortbay.jetty.webapp.WebAppContext;
@@ -32,9 +32,9 @@ object JettyStarter {
3232
val bb = new WebAppContext();
3333
bb.setServer(server);
3434
bb.setContextPath("/");
35-
bb.setWar("submitit-webapp/src/main/webapp");
35+
bb.setWar(webappDir.toString);
3636

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)
3838

3939
server.addHandler(bb);
4040

@@ -53,4 +53,31 @@ object JettyStarter {
5353
}
5454
}
5555
}
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+
}
5683
}

0 commit comments

Comments
 (0)