You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by David Schlotfeldt <tc...@plauditdesign.com> on 2006/03/03 05:01:28 UTC

getResource giving filenotfound

I have a property file in WEB-INF. I thought this is how you get to it:

URL configUrl = 
FacesContext.getCurrentInstance().getExternalContext().getResource("/WEB-INF/test.properties");
...
configProperties.load(new FileInputStream(file));


But I get this exception

============================
Caused by: java.io.FileNotFoundException: 
jndi:\localhost\test.biz\WEB-INF\test.properties (The filename, 
directory name, or volume label syntax is incorrect)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:106)
        at biz.test.site.TestFacade.<init>(TestFacade.java:129)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native 
Method)
        at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
        at java.lang.Class.newInstance0(Class.java:350)
        at java.lang.Class.newInstance(Class.java:303)
        at 
org.apache.myfaces.shared_impl.util.ClassUtils.newInstance(ClassUtils.java:274)
        at 
org.apache.myfaces.shared_impl.util.ClassUtils.newInstance(ClassUtils.java:265)
        at 
org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:50)
        at 
org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:311)
        at 
org.apache.myfaces.config.LastVariableResolverInChain.resolveVariable(LastVariableResolverInChain.java:42)
        at 
com.sun.facelets.el.LegacyELContext$LegacyELResolver.getValue(LegacyELContext.java:134)
        at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
        at com.sun.el.parser.AstValue.getValue(AstValue.java:85)
        at 
com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:183)
        at 
com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
        at 
com.sun.facelets.tag.TagAttribute.getObject(TagAttribute.java:233)
        ... 39 more
==========================

Why is it looking in jndi?
What am I doing wrong?

Thanks,
David



Re: getResource giving filenotfound

Posted by David Schlotfeldt <tc...@plauditdesign.com>.
Thank you. I will try this out.

Isn't what I did suppose to work? I thought you aren't suppose to use 
the servlet objects directly since it ties you to using your JSF 
application in a servlet container. (Personally, what you gave me is 
perfectly find with me. And it's not like I would ever use it outside of 
a servlet... well.. excet if I make some test cases.)

David

Anthony Hong wrote:

>String filePath =
>((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext()).getRealPath("/WEB-INF/test.properties");
>You can get correct file path.
>
>On 3/3/06, David Schlotfeldt <tc...@plauditdesign.com> wrote:
>  
>
>>I have a property file in WEB-INF. I thought this is how you get to it:
>>
>>URL configUrl =
>>FacesContext.getCurrentInstance().getExternalContext().getResource("/WEB-INF/test.properties");
>>...
>>configProperties.load(new FileInputStream(file));
>>
>>
>>But I get this exception
>>
>>============================
>>Caused by: java.io.FileNotFoundException:
>>jndi:\localhost\test.biz\WEB-INF\test.properties (The filename,
>>directory name, or volume label syntax is incorrect)
>>       at java.io.FileInputStream.open(Native Method)
>>       at java.io.FileInputStream.<init>(FileInputStream.java:106)
>>       at biz.test.site.TestFacade.<init>(TestFacade.java:129)
>>       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
>>Method)
>>       at
>>sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>>       at
>>sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>>       at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
>>       at java.lang.Class.newInstance0(Class.java:350)
>>       at java.lang.Class.newInstance(Class.java:303)
>>       at
>>org.apache.myfaces.shared_impl.util.ClassUtils.newInstance(ClassUtils.java:274)
>>       at
>>org.apache.myfaces.shared_impl.util.ClassUtils.newInstance(ClassUtils.java:265)
>>       at
>>org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:50)
>>       at
>>org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:311)
>>       at
>>org.apache.myfaces.config.LastVariableResolverInChain.resolveVariable(LastVariableResolverInChain.java:42)
>>       at
>>com.sun.facelets.el.LegacyELContext$LegacyELResolver.getValue(LegacyELContext.java:134)
>>       at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
>>       at com.sun.el.parser.AstValue.getValue(AstValue.java:85)
>>       at
>>com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:183)
>>       at
>>com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
>>       at
>>com.sun.facelets.tag.TagAttribute.getObject(TagAttribute.java:233)
>>       ... 39 more
>>==========================
>>
>>Why is it looking in jndi?
>>What am I doing wrong?
>>
>>Thanks,
>>David
>>
>>
>>
>>    
>>
>
>
>--
>
>Anthony Hong
>
>  
>

Re: getResource giving filenotfound

Posted by Anthony Hong <an...@gmail.com>.
String filePath =
((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext()).getRealPath("/WEB-INF/test.properties");
You can get correct file path.

On 3/3/06, David Schlotfeldt <tc...@plauditdesign.com> wrote:
> I have a property file in WEB-INF. I thought this is how you get to it:
>
> URL configUrl =
> FacesContext.getCurrentInstance().getExternalContext().getResource("/WEB-INF/test.properties");
> ...
> configProperties.load(new FileInputStream(file));
>
>
> But I get this exception
>
> ============================
> Caused by: java.io.FileNotFoundException:
> jndi:\localhost\test.biz\WEB-INF\test.properties (The filename,
> directory name, or volume label syntax is incorrect)
>        at java.io.FileInputStream.open(Native Method)
>        at java.io.FileInputStream.<init>(FileInputStream.java:106)
>        at biz.test.site.TestFacade.<init>(TestFacade.java:129)
>        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> Method)
>        at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>        at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>        at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
>        at java.lang.Class.newInstance0(Class.java:350)
>        at java.lang.Class.newInstance(Class.java:303)
>        at
> org.apache.myfaces.shared_impl.util.ClassUtils.newInstance(ClassUtils.java:274)
>        at
> org.apache.myfaces.shared_impl.util.ClassUtils.newInstance(ClassUtils.java:265)
>        at
> org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:50)
>        at
> org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:311)
>        at
> org.apache.myfaces.config.LastVariableResolverInChain.resolveVariable(LastVariableResolverInChain.java:42)
>        at
> com.sun.facelets.el.LegacyELContext$LegacyELResolver.getValue(LegacyELContext.java:134)
>        at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
>        at com.sun.el.parser.AstValue.getValue(AstValue.java:85)
>        at
> com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:183)
>        at
> com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
>        at
> com.sun.facelets.tag.TagAttribute.getObject(TagAttribute.java:233)
>        ... 39 more
> ==========================
>
> Why is it looking in jndi?
> What am I doing wrong?
>
> Thanks,
> David
>
>
>


--

Anthony Hong