Add resources to Jetty programmatically

后端 未结 2 694
梦谈多话
梦谈多话 2021-02-09 07:27

I have a main class that configures and fires up Jetty. (That\'s standard practice from Wicket for testing a webapp, but it\'s really not wicket-specific.)

final         


        
2条回答
  •  無奈伤痛
    2021-02-09 08:22

    Add a WebAppContext for each virtual directory:

    final Server server = new Server();
    //skipped socketconnector initialization
    
    final WebAppContext js = new WebAppContext();
    js.setServer(server);
    js.setContextPath("/js");
    js.setWar("target/classes/js"); // or whatever the correct path is in your case
    server.addHandler(js);
    
    // css the same way
    
    final WebAppContext bb = new WebAppContext();
    bb.setServer(server);
    bb.setContextPath("/");
    bb.setWar("src/main/webapp");
    server.addHandler(bb);
    
    server.start();
    

提交回复
热议问题