Solved

null value returned for the url

Posted on 2011-09-08
6
236 Views
Last Modified: 2012-05-12
We are using server side java with blazeDS for our current project, and are using class.getClassLoader().getResource("fileName"), but we are getting a null value returned for the url.  We have placed "fileName" with the .class files on the server, but it seems like it is unable to find the file.  Is there something we are missing, maybe in setting up the project?


thanks
0
Comment
Question by:anotherfn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36505748
Is it inside the WEB-INF folder?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36505756
If you use

this.getClass().getClassLoader().getResource("fileName")

then my understanding is that you should be putting your class inside the pacjage of class of your instance this - are you doing it this way ?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36505905
I'm sorry I was not right in my previous post - actually

URL url = this.getClass().getClassLoader().getResource("fileName");

This will be looking at the root of your classpath for class of intsnce this


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 47

Expert Comment

by:for_yan
ID: 36505926

So if your class of this is
com.company.pack.MyClass

then your MyClass.class will be in the fiolder

com/company/pack

however this

URL url = this.getClass().getClassLoader().getResource("fileName.txt");

will be looking for file  fileName.txt
in the folder above com

if you put it alongside with class fiile MyClass
the you shoud say:

URL url = this.getClass().getClassLoader().getResource("com/company/pack/fileName.txt");

Otherwise it returns null

I juts tested it and it works that way





0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 36505940
I think it should work the same way, no matter if it is in regular applcation or in J2EE or app server
or anything because this is how these methods should work according to specification
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36506975
Please post your code and tell us where you file is
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question