在嵌入式Jetty中部署网页以及Restful

时间:2019-01-31 10:09:11

标签: java server jetty

如何在Embedded Jetty中将网页以及我的Restful Project一起部署?

我已经设置了Jetty项目以使用嵌入式码头来部署RESTFUL。

public class App {

private static Server server;

public static void main(String...s) {
    initJetty();
}

private static void initJetty(){
    try {
        URI baseUri = UriBuilder.fromPath(System.getProperty("jetty.uri", "http://127.0.0.1:32081")).build();
        server = JettyHttpContainerFactory.createServer(baseUri, new AppResourceConfig());
        server.start();

    } catch(Exception ex){
        stopJetty();
    }

}

private static void stopJetty() {

    if(server != null){
        try {
            server.stop();
        } catch (Exception e) {

        }
    }
}
}


public class AppResourceConfig extends ResourceConfig {
private static final String REST_BASE_PACKAGE = "com.dinesh.client.endpoints";

public AppResourceConfig(){
    //Base package suffices as it scans all the subpackages recursively.
    packages(REST_BASE_PACKAGE)
    .register(MultiPartFeature.class)
    .register(MoxyJsonFeature.class);
}
}

如何使用嵌入式码头在同一端口上部署网页?我希望能够在终端上使用java -jar命令进行部署。

1 个答案:

答案 0 :(得分:0)

尝试将码头赛跑者用于战争/野蛮人/耳朵

java -jar jetty-runner-9.4.0.M1.jar jetty-app/target/jetty-app.war