如何从JSF中的服务器中的JAR获取图像或js(对于自定义组件) [英] How to get an image or js from a JAR in the server in JSF (For a custom component)
问题描述
我已经完成了一个自定义的JSF组件(它看起来像一个组合框(icefaces selectonemenu))但它使用了几个图像(png)和一些javascript。
我把所有内容都包装好,然后开发人员将它用作在web-inf / lib文件夹中复制的jar。
图像和js只适用于这个自定义组件,因此我不能让它们将这个图像和js放在他的项目中,它必须在我的jar中。
我把所有东西都包装好,它的效果差不多,只是图像和JS,我不让它们起作用。我不知道如何在罐子里引用它们。只要它们是应用程序的一部分,我就可以让它们工作,但不能成为jar的一部分。
我应该如何在我的编码链接代码中使用它们?
我正在使用带有icefaces的JSF 1.8
提前致谢!!
如果您已经使用过JSF 2.0,它应该可以正常运行您使用 时的框@ResourceDependency
或 @ResourceDependencies
注释,可根据JAR的 / META-INF / resources
文件夹解析资源。 / p>
在JSF 1.x上,最好的办法是创建一个映射到某个URL模式的自定义资源servlet,例如: /com.nahiko.resources / *
并将资源从类路径流式传输到HTTP响应。基本启动示例:
String path =/ META-INF / resources+ request.getPathInfo();
InputStream input = getClass()。getResourceAsStream(path);
OutputStream output = response.getOutputStream();
// ... ...
在您的JAR上记录此servlet必须映射的文档。或者,如果您定位Servlet 3.0容器,只需添加 @WebServlet
注释即可自动注册。
I have done a custom JSF component (it looks like a combobox (icefaces selectonemenu)) but it uses a couple of images (png) and a bit of javascript. I jar everything, so then the developers use it as a jar copied in the web-inf/lib folder. The image and the js are just for this custom component, so I can't make them put this image and js in his project, it has to be in MY jar.
I jar everything and it works almost great, just the image and the JS, I do not get them to work. I do not know how to reference them being in the jar. I could make them work as long as they are part of the application, but not being part of the jar. How should I do to get them in my encodebegin code for example?
I am using JSF with icefaces 1.8
Thanks in advance!!
If you're already on JSF 2.0, it should work just fine out the box when you're using @ResourceDependency
or @ResourceDependencies
annotation which can resolve resources based on JAR's /META-INF/resources
folder.
On JSF 1.x, your best bet is to create a custom "resource servlet" which is mapped on a certain URL pattern, e.g. /com.nahiko.resources/*
and just streams the resources from the classpath to the HTTP response. Basic kickoff example:
String path = "/META-INF/resources" + request.getPathInfo();
InputStream input = getClass().getResourceAsStream(path);
OutputStream output = response.getOutputStream();
// ...
Document along your JAR that this servlet has to be mapped. Or if you target a Servlet 3.0 container, just add the @WebServlet
annotation to get it to auto-register.
这篇关于如何从JSF中的服务器中的JAR获取图像或js(对于自定义组件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!