I have a bean class where I'm using a file that I've placed in application/WebContent/common
folder. I have been refering to this file as below
我有一个bean类,我正在使用我放在application / WebContent / common文件夹中的文件。我一直在推荐这个文件如下
File xsltfile = new File("../common/xhtml2fo.xsl");
in my eclipse, with my working directory configured to
在我的eclipse中,我的工作目录配置为
${workspace_loc:enovia/WebContent/WEB-INF}
it worked fine. However, while testing it on a domain-box, I'm getting a file not found exception because its looking for the file in {tomcat-path}/bin/../common/xhtml2fo.xsl.
它工作得很好。但是,在域框上测试它时,我得到一个文件未找到异常,因为它在{tomcat-path} / bin /../ common / xhtml2fo.xsl中查找该文件。
I don't have access to bean classes in the domain box. So my only option for now is to change my tomcat working directory to WEB-INF.
我无法访问域框中的bean类。所以我现在唯一的选择是将我的tomcat工作目录更改为WEB-INF。
1 个解决方案
#1
You can read files in WEB-INF
using this approach:
您可以使用以下方法读取WEB-INF中的文件:
InputStream in = Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream( "xhtml2fo.xsl" );
or even simpler if you're in a servlet:
如果你在servlet中,甚至更简单:
getServletContext().getResourceAsStream( "/WEB-INF/xhtml2fo.xsl" )
Cheers,
#1
You can read files in WEB-INF
using this approach:
您可以使用以下方法读取WEB-INF中的文件:
InputStream in = Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream( "xhtml2fo.xsl" );
or even simpler if you're in a servlet:
如果你在servlet中,甚至更简单:
getServletContext().getResourceAsStream( "/WEB-INF/xhtml2fo.xsl" )
Cheers,