You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Timothy Washington <ti...@yahoo.ca> on 2009/03/08 03:53:30 UTC
java.lang.NullPointerException loading resource from classpath
Hi there, I have what seems to be a very simple problem.
I've deployed a web application to tomcat. But in the application, when I try to load a resource (an XML file), it comes back as null. This is very frustrating, because some of the most basic approaches are not working to give me my XML resource. I'm using the 'MyClass.class.getResourceAsStream("myresource.xml")' method, and I've tried the following:
* placing the resource in i) WEB-INF/lib, ii) WEB-INF/classes
* using tomcat versions i) 5.5.27 and ii) 6.0.18
* setting the classpath in i) conf/catalina.properties ii) manually in bin/catalina.sh
Can anyone help me here? This should be dead simple, so I feel like I'm missing something basic.
Thanks
Tim
__________________________________________________________________
Instant Messaging, free SMS, sharing photos and more... Try the new Yahoo! Canada Messenger at http://ca.beta.messenger.yahoo.com/
Re: java.lang.NullPointerException loading resource from classpath
Posted by Pid <p...@pidster.com>.
Timothy Washington wrote:
>
> Hi there, I have what seems to be a very simple problem.
>
> I've deployed a web application to tomcat. But in the application, when I try to load a resource (an XML file), it comes back as null. This is very frustrating, because some of the most basic approaches are not working to give me my XML resource. I'm using the 'MyClass.class.getResourceAsStream("myresource.xml")' method, and I've tried the following:
> * placing the resource in i) WEB-INF/lib, ii) WEB-INF/classes
> * using tomcat versions i) 5.5.27 and ii) 6.0.18
> * setting the classpath in i) conf/catalina.properties ii) manually in bin/catalina.sh
Setting the classpath is a bad idea, don't do it.
Tomcat sets its own classpath & the classpath for individual web
applications, any tinkering you do is likely to produce unpredictable
conditions.
Place the resource in WEB-INF/classes and make sure your class has a
package definition. Let us know if that works.
p
> Can anyone help me here? This should be dead simple, so I feel like I'm missing something basic.
>
> Thanks
> Tim
>
>
>
> __________________________________________________________________
> Instant Messaging, free SMS, sharing photos and more... Try the new Yahoo! Canada Messenger at http://ca.beta.messenger.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: java.lang.NullPointerException loading resource from classpath
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Tim,
On 3/7/2009 9:53 PM, Timothy Washington wrote:
> 'MyClass.class.getResourceAsStream("myresource.xml")'
You might have better luck using ServletContext.getResourceAsStream, if
you have access to the ServletContext.
Check out the javadoc for this method for more information.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkm4LKcACgkQ9CaO5/Lv0PAG1wCgk3Zkmt6yLQA8qf5UctxRIRS0
rU4An3HIX/Ggox41DqktOFvRjWBrOFtZ
=o8q1
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: java.lang.NullPointerException loading resource from classpath
Posted by Timothy Washington <ti...@yahoo.ca>.
Nope!!! I lied, it's still not working in tomcat 4 :|
tim
________________________________
From: Timothy Washington <ti...@yahoo.ca>
To: Tomcat Users List <us...@tomcat.apache.org>
Sent: Saturday, March 7, 2009 10:19:16 PM
Subject: Re: java.lang.NullPointerException loading resource from classpath
Update:
I tried this webapp in 'apache-tomcat-4.1.39-LE-jdk14' and the code in question works fine. So my question is what happened to tomcat 5 and after that makes resource loading so difficult?
It's a very simple call to 'MyClass.class.getResourceAsStream("myresource.xml")' and the resource is definitely present.
Thanks
Tim
________________________________
From: Timothy Washington <ti...@yahoo.ca>
To: users@tomcat.apache.org
Sent: Saturday, March 7, 2009 9:53:30 PM
Subject: java.lang.NullPointerException loading resource from classpath
Hi there, I have what seems to be a very simple problem.
I've deployed a web application to tomcat. But in the application, when I try to load a resource (an XML file), it comes back as null. This is very frustrating, because some of the most basic approaches are not working to give me my XML resource. I'm using the 'MyClass.class.getResourceAsStream("myresource.xml")' method, and I've tried the following:
* placing the resource in i) WEB-INF/lib, ii) WEB-INF/classes
* using tomcat versions i) 5.5.27 and ii) 6.0.18
* setting the classpath in i) conf/catalina.properties ii) manually in bin/catalina.sh
Can anyone help me here? This should be dead simple, so I feel like I'm missing something basic.
Thanks
Tim
__________________________________________________________________
Instant Messaging, free SMS, sharing photos and more... Try the new Yahoo! Canada Messenger at http://ca.beta.messenger.yahoo.com/
__________________________________________________________________
Instant Messaging, free SMS, sharing photos and more... Try the new Yahoo! Canada Messenger at http://ca.beta.messenger.yahoo.com/
__________________________________________________________________
Ask a question on any topic and get answers from real people. Go to Yahoo! Answers and share what you know at http://ca.answers.yahoo.com
Re: java.lang.NullPointerException loading resource from classpath
Posted by Timothy Washington <ti...@yahoo.ca>.
Update:
I tried this webapp in 'apache-tomcat-4.1.39-LE-jdk14' and the code in question works fine. So my question is what happened to tomcat 5 and after that makes resource loading so difficult?
It's a very simple call to 'MyClass.class.getResourceAsStream("myresource.xml")' and the resource is definitely present.
Thanks
Tim
________________________________
From: Timothy Washington <ti...@yahoo.ca>
To: users@tomcat.apache.org
Sent: Saturday, March 7, 2009 9:53:30 PM
Subject: java.lang.NullPointerException loading resource from classpath
Hi there, I have what seems to be a very simple problem.
I've deployed a web application to tomcat. But in the application, when I try to load a resource (an XML file), it comes back as null. This is very frustrating, because some of the most basic approaches are not working to give me my XML resource. I'm using the 'MyClass.class.getResourceAsStream("myresource.xml")' method, and I've tried the following:
* placing the resource in i) WEB-INF/lib, ii) WEB-INF/classes
* using tomcat versions i) 5.5.27 and ii) 6.0.18
* setting the classpath in i) conf/catalina.properties ii) manually in bin/catalina.sh
Can anyone help me here? This should be dead simple, so I feel like I'm missing something basic.
Thanks
Tim
__________________________________________________________________
Instant Messaging, free SMS, sharing photos and more... Try the new Yahoo! Canada Messenger at http://ca.beta.messenger.yahoo.com/
__________________________________________________________________
Instant Messaging, free SMS, sharing photos and more... Try the new Yahoo! Canada Messenger at http://ca.beta.messenger.yahoo.com/