以编程方式向Jetty添加资源

编程入门 行业动态 更新时间:2024-10-26 18:19:49
本文介绍了以编程方式向Jetty添加资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个主类来配置和激活Jetty。 (这是Wicket测试webapp的标准做法,但它确实不是特定于wicket的。)

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 Server server = new Server(); //skipped socketconnector initialization final WebAppContext bb = new WebAppContext(); bb.setServer(server); bb.setContextPath("/"); bb.setWar("src/main/webapp"); server.addHandler(bb); server.start();

如您所见,src / main / webapp用作webapp root。但是,我有一些目标/类中的资源,稍后会复制到webapp。所以我想将虚拟目录添加到jetty。

As you can see, src/main/webapp is used as webapp root. However, I have some resources that are in target/classes and that are copied to the webapp later. So I would like to add virtual directories to jetty.

我想映射 target / classes / js 到 / js 和 target / classes / css 到 / css

有人可以提供帮助吗?

BTW:它是码头6.1.4

BTW: it's jetty 6.1.4

推荐答案

为每个虚拟目录添加 WebAppContext :

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();

更多推荐

以编程方式向Jetty添加资源

本文发布于:2023-11-12 18:41:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582239.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   资源   Jetty

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!