本文介绍了以编程方式向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添加资源
发布评论