Solved

null value returned for the url

Posted on 2011-09-08
6
232 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
GUI builder for Eclipse? 8 35
eclipse argument 14 60
Java SE 8u111  Lot of stuff broke 11 69
servlet  URL Rewriting 1 36
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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.

776 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