由于我无法在 gradle 构建级别找到好的解决方案,我决定使用嵌入式码头。这是scala类:
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.webapp.WebAppContext
import org.eclipse.jetty.server.bio.SocketConnector
object JettyServer {
def main(args: Array[String]) {
val server = new Server
val context = new WebAppContext
val connector = new SocketConnector
connector.setMaxIdleTime(1000 * 60 * 60)
connector.setPort(8080)
context.setServer(server)
context.setWar(args(0))
server.setConnectors(Array(connector))
server.setHandler(context)
try {
server.start();
server.join();
} catch {
case e: Exception => e.printStackTrace();
}
}
}
然后在 build.gradle 中:
apply plugin: "application"
mainClassName = "com.mycompany.myproject"
run.args = [war.archivePath]
task jettyRun(dependsOn: run)
一切正常:)