COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### getResourceAsStream() problem

• Email
• Follow

Hello, I have a problem with getResourceAsStream().

I'm using these tools: Eclipse JEE edition version 3.5.1 with the Apache
CXF plugin and Apache Tomcat version 6.0.20. Java is version 6. This is
under Windows.

I've written a very simple JAX-WS web service, here's the complete code:

package bioweb;

import java.rmi.Remote;
import java.rmi.RemoteException;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService(name="BioWebInterface", targetNamespace="http://bioweb/")
public interface BioWebInterface extends Remote {
@WebMethod(operationName="sayHello", action="urn:SayHello")
public String sayHello() throws RemoteException;
}

package bioweb;

import java.io.InputStream;
import java.rmi.RemoteException;

import javax.annotation.PostConstruct;
import javax.jws.WebService;

@WebService(targetNamespace="http://bioweb/",
endpointInterface="bioweb.BioWebInterface", portName="BioWebPort",
serviceName="BioWebService")
public class BioWeb implements BioWebInterface {

@Override
public String sayHello() throws RemoteException {
return "Hello from the BioWeb Web Service!";
}

@PostConstruct
protected void init() {
System.out.println("I'm in the postconstruct method.");

InputStream is1 =
InputStream is2 =

if (is1 != null && is2 != null) {
methods!");
}
else if (is1 != null) {
1.");
}
else if (is2 != null) {
2.");
}
else {
resource!");
}
}

/**
* @param args
*/
public static void main(String[] args) {
new BioWeb().init();
}
}

I've created folder called xqueries and added it to the classpath (under
project properties->java build path->libraries tab->add class folder
button and in it I have an XQuery file named get-all-model-links.xquery
(will be lots more later).

When I run the BioWeb class like a normal Java program (by invoking
main(), which calls init(), I can load the XQuery resource fine, the
output is:
I'm in the postconstruct method.
Successfully loaded resource using both methods!

However, when run as a service (then Tomcat calls the init() method due
The output is:
I'm in the postconstruct method.

It seems that the class folder I added isn't visible anymore or maybe
the "URL:s" need to be altered when in this context. I'm very new at
this web stuff and I need help, I've had this problem for two days now. :(
I'm doing all the interfacing with Tomcat via Eclipse btw, and I haven't
really tampered with any settings for it.

Thanks for reading and for any replies!

- Fencer

 0

See related articles to this posting

On 2010-01-27 16:02, Fencer wrote:
> Hello, I have a problem with getResourceAsStream().
[snip my OP]

I believe I solved this problem!

- Fencer

 0

On 1/27/2010 7:48 AM, Fencer wrote:
> On 2010-01-27 16:02, Fencer wrote:
>> Hello, I have a problem with getResourceAsStream().
> [snip my OP]
>
> I believe I solved this problem!
It is often considered courteous to explain how you solved your problem.

Others may find your post while looking into a similar problem, and
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

 0

Fencer wrote:
> Hello, I have a problem with getResourceAsStream().
>
> [snip my OP]
>
> I believe I solved this problem!
>

Thank you so much for sharing the solution so that others besides
yourself may benefit!

--
Lew

 0

On Wed, 27 Jan 2010 16:48:11 +0100, Fencer
<no.i.dont@want.mail.from.spammers.com> wrote, quoted or indirectly
quoted someone who said :

>
>I believe I solved this problem!

Some day someone will have the same problem as you, find you question

--
http://mindprod.com
Computers are useless. They can only give you answers.
~ Pablo Picasso (born: 1881-10-25 died: 1973-04-08 at age: 91)

 0

On 2010-01-27 16:48, Fencer wrote:
> On 2010-01-27 16:02, Fencer wrote:
>> Hello, I have a problem with getResourceAsStream().
> [snip my OP]
>
> I believe I solved this problem!
>
> - Fencer

Hello again. I wish to offer my sincere apologies for not specifying the
details of my solution in my previous post.

The problem turned out to be not in the actual Java code but in how I
was using my tools. Adding a directory to the classpath in the Eclipse
project settings didn't propagate to Tomcat in my context. What I did
was to add the directory to the classpath to Tomcat's launch
configuration under Eclipse. That solved it!

If you you doubleclick on the Tomcat server under the Server tab (in the
window that usually holds tabs like console, problems etc, I'm not sure
what it's called), an "Overview" of settings should open. There's a link
there "Open Launch Configuration" which opens a configuration dialog.
The dialog has a tab called "classpath" and you can add your entry
there, under "User Entries".

Again, I apologise for not writing this the first time around and thanks
to those who reminded me to do so.

- Fencer

 0

On Jan 28, 10:26=A0am, Fencer <no.i.d...@want.mail.from.spammers.com>
wrote:
> On 2010-01-27 16:48, Fencer wrote:
>
> > On 2010-01-27 16:02, Fencer wrote:
> >> Hello, I have a problem with getResourceAsStream().
> > [snip my OP]
>
> > I believe I solved this problem!
>
> > - Fencer
>
> Hello again. I wish to offer my sincere apologies for not specifying the
> details of my solution in my previous post.
>
> The problem turned out to be not in the actual Java code but in how I
> was using my tools. Adding a directory to the classpath in the Eclipse
> project settings didn't propagate to Tomcat in my context. What I did
> was to add the directory to the classpath to Tomcat's launch
> configuration under Eclipse. That solved it!
>
> If you you doubleclick on the Tomcat server under the Server tab (in the
> window that usually holds tabs like console, problems etc, I'm not sure
> what it's called), an "Overview" of settings should open. There's a link
> there "Open Launch Configuration" which opens a configuration dialog.
> The dialog has a tab called "classpath" and you can add your entry
> there, under "User Entries".
>

You're supposed to include libraries needed by a web app in the "lib/"
directory of the web app.

You shouldn't entirely depend on the IDE to specify a class path.  You
should be able to deploy the application from the command line.

--
Lew

 0

On 2010-01-28 20:29, Lew wrote:
>>
>
> You're supposed to include libraries needed by a web app in the "lib/"
> directory of the web app.
>
> You shouldn't entirely depend on the IDE to specify a class path.  You
> should be able to deploy the application from the command line.

Thanks for your reply, Lew, and you make a dood point. There are several
jar-files in my WebContent->WEB-INF->lib folder, but if I put my XQuery
file in there, getResourceAsStream() doesn't find it :(

If I could make it work without adding a directory to classpath like I'm
doing that would be even better!

- Fencer

 0

Fencer wrote:
> Thanks for your reply, Lew, and you make a dood point. There are several
> jar-files in my WebContent->WEB-INF->lib folder, but if I put my XQuery
> file in there, getResourceAsStream() doesn't find it :(
>
> If I could make it work without adding a directory to classpath like I'm
> doing that would be even better!

There are already several directories in your class path for a web app.

Is your "XQuery file" a JAR?  No?  Then it doesn't go in the "lib/" directory.

The root directory of your application ("application-name/") and the classes
your resource relative to one of those.

--
Lew

 0

On Thu, 28 Jan 2010 16:26:34 +0100, Fencer
<no.i.dont@want.mail.from.spammers.com> wrote, quoted or indirectly
quoted someone who said :

>
>Again, I apologise for not writing this the first time around and thanks
>to those who reminded me to do so.

Thank you for sharing your solution rather than getting defensive as a
normal person would.
--
http://mindprod.com
Computers are useless. They can only give you answers.
~ Pablo Picasso (born: 1881-10-25 died: 1973-04-08 at age: 91)

 0

On 2010-01-29 04:11, Lew wrote:
> Fencer wrote:
>> Thanks for your reply, Lew, and you make a dood point. There are
>> several jar-files in my WebContent->WEB-INF->lib folder, but if I
>> put my XQuery file in there, getResourceAsStream() doesn't find it
>> :(
>>
>> If I could make it work without adding a directory to classpath
>> like I'm doing that would be even better!
>
> There are already several directories in your class path for a web
> app.
>
> Is your "XQuery file" a JAR? No? Then it doesn't go in the "lib/"
> directory.

No, it's a text file containing code written in the XQuery (an XML query
language), I should have detailed that better in my OP. That's why I
didn't put it in the lib directory (however, I did put the Saxon
jar-file there which I use for running XQuery).

>
> The root directory of your application ("application-name/") and the
>  classes directory ("application-name/WEB-INF/classes/") are already
> in your path. Put your resource relative to one of those.
>

I can't check right now but I believe I already put the file in the
project root but I still couldn't load it. I will try again a little later.

Can I get runtime information on which directories are in the classpath?

- Fencer

 0

Fencer wrote:
> On 2010-01-29 04:11, Lew wrote:
>> Fencer wrote:
>>> Thanks for your reply, Lew, and you make a dood point. There are
>>> several jar-files in my WebContent->WEB-INF->lib folder, but if I
>>> put my XQuery file in there, getResourceAsStream() doesn't find it
>>> :(
>>>
>>> If I could make it work without adding a directory to classpath
>>> like I'm doing that would be even better!
>>
>> There are already several directories in your class path for a web
>> app.
>>
>> Is your "XQuery file" a JAR? No? Then it doesn't go in the "lib/"
>> directory.
>
> No, it's a text file containing code written in the XQuery (an XML
> query language), I should have detailed that better in my OP. That's
> why I didn't put it in the lib directory (however, I did put the
> Saxon
> jar-file there which I use for running XQuery).
>
>>
>> The root directory of your application ("application-name/") and
>> the
>>  classes directory ("application-name/WEB-INF/classes/") are
>> in your path. Put your resource relative to one of those.
>>
>
> I can't check right now but I believe I already put the file in the
> project root but I still couldn't load it. I will try again a little
> later.

I don't think the project root is in the classpath.   The normal wasy
to make a resource available is

1. Put it below WEB-INF/classes, e.g. a resource named a/b/c.xml would
go at WEB-INF/classes/a/b/c.xml
2. Put it into a jar file, and put the jar file into WEB-INF/lib


 0

Mike Schilling wrote:
> I don't think the project root is in the classpath.   The normal wasy
> to make a resource available is

Depends on which of the three types of 'getResource*' methods you use.  Those
in 'javax.servlet.ServletContext' include the project root.

--
Lew

 0

Lew wrote:
> Mike Schilling wrote:
>> I don't think the project root is in the classpath.   The normal
>> wasy
>> to make a resource available is
>
> Depends on which of the three types of 'getResource*' methods you
> use.  Those in 'javax.servlet.ServletContext' include the project
> root.

That you need to call a method on a completely different class is a
critical bit of information to omit.  And it remains true that the
project root is not in the classpath.


 0

In article <hjuome$p2l$1@news.albasani.net>, Lew <noone@lewscanon.com>
wrote:

> Mike Schilling wrote:
> > I don't think the project root is in the classpath.   The normal wasy
> > to make a resource available is
>
> Depends on which of the three types of 'getResource*' methods you use.  Those
> in 'javax.servlet.ServletContext' include the project root.

In this context, does "three types" mean those "getResource*" methods
found in java.lang, java.beans.beancontext, and javax.servlet?

--
John B. Matthews
trashgod at gmail dot com

 0

John B. Matthews wrote:
> In article <hjuome$p2l$1@news.albasani.net>, Lew <noone@lewscanon.com>
> wrote:
>
>> Mike Schilling wrote:
>>> I don't think the project root is in the classpath.   The normal wasy
>>> to make a resource available is
>> Depends on which of the three types of 'getResource*' methods you use.  Those
>> in 'javax.servlet.ServletContext' include the project root.
>
> In this context, does "three types" mean those "getResource*" methods
> found in java.lang, java.beans.beancontext, and javax.servlet?

Four!

I had in mind Class, ClassLoader and ServletContext.  Packages don't have methods.

--
Lew

 0

On 29-01-2010 18:56, Lew wrote:
> John B. Matthews wrote:
>> In article <hjuome$p2l$1@news.albasani.net>, Lew <noone@lewscanon.com>
>> wrote:
>>> Mike Schilling wrote:
>>>> I don't think the project root is in the classpath. The normal wasy
>>>> to make a resource available is
>>> Depends on which of the three types of 'getResource*' methods you
>>> use. Those in 'javax.servlet.ServletContext' include the project root.
>>
>> In this context, does "three types" mean those "getResource*" methods
>> found in java.lang, java.beans.beancontext, and javax.servlet?
>
> Four!
>
> I had in mind Class, ClassLoader and ServletContext. Packages don't have
> methods.

No, but you know perfectly well what he means.

Arne


 0

John B. Matthews wrote:
>>> In this context, does "three types" mean those "getResource*" methods
>>> found in java.lang, java.beans.beancontext, and javax.servlet?

Lew wrote:
>> Four!
>>
>> I had in mind Class, ClassLoader and ServletContext. Packages don't have
>> methods.

Arne Vajhøj wrote:
> No, but you know perfectly well what he means.

--
Lew

 0

In article <hjvtht$qpt$3@news.albasani.net>, Lew <noone@lewscanon.com>
wrote:

> John B. Matthews wrote:
> >>> In this context, does "three types" mean those "getResource*"
> >>> methods found in java.lang, java.beans.beancontext, and
> >>> javax.servlet?
>
> Lew wrote:
> >> Four!
> >>
> >> don't have methods.
>
> Arne Vajhøj wrote:
> > No, but you know perfectly well what he means.
>

I thank you both for clearing that up. I had tried asterisks as
wildcards, but the meaning was even less clear.

I was intrigued by how the three packages implement the notion of
getting a resource: ClassLoader is foundational, while the bean approach
"allows a BeanContext implementation to interpose behavior between the
child Component and underlying ClassLoader." The ServletContext
implementation "does not use class loaders" at all but serves a similar
purpose relative to the servlet container's context.

This seems like a handy pattern to put in one's hip pocket.

--
John B. Matthews
trashgod at gmail dot com

 0

On 29-01-2010 19:12, Lew wrote:
> John B. Matthews wrote:
>>>> In this context, does "three types" mean those "getResource*" methods
>>>> found in java.lang, java.beans.beancontext, and javax.servlet?
>
> Lew wrote:
>>> Four!
>>>
>>> I had in mind Class, ClassLoader and ServletContext. Packages don't have
>>> methods.
>
> Arne Vajhøj wrote:
>> No, but you know perfectly well what he means.
>

I don't think there were any reason to point out the obvious.

Arne


 0

19 Replies
569 Views

Similar Articles

12/6/2013 6:05:06 AM
page loaded in 49833 ms. (0)

Similar Artilces:

Problem
On the right side of my screen (the cover) i can see light goes through a little schrink. 2 weeks laptop Is it normal or i shoul exchange it.... Thanks

Problem with templates
of text - I'll simply assume that you got the syntax right. If I were you, I'd have tried to create the smallest possible piece of code that still shows the problem, without a complex combo of memberfunction pointers in template argument lists. > This is implemented in another cpp file [...] > This is compiled into a .lib file > and the fucntion is called from another cpp file which implements a > class called Bond and it has a public method > This is also compiled into a .lib and referenced in a consol app. I am > getting the linker error when trying to create

dispatch problem
How can i send my aglets to other hosts in my network. I tried sending my aglets by providing atp://<ip-address> few were successfully dispatched but were not able retract back. when i tried to send others i got this error com.ibm.aglet.RequestRefusedException atp://192.168.0255,Integrity=DIGEST,Confidentiality=SHORTSECRETKEY,Timeout=0 examples.snmp.SnmpGet please suggest if there are any settings to be done!

problem with mexCallMATLAB
= *ouptr; If I used to debug the program, the value of single should come 1. But unfortunatly the value of single is coming to 0 only. Any comment will be appreciated. Nihal Hi Nihal, without testing your code, I think your line int *ouptr, single; is the problem. The value is 1, but it is not an integer, but of type double (as all MATLAB-variables, as long as you don't explicitly set the type like uint32(1)). So double *ouptr, single; and ouptr = mxGetPr(ouhs[0]); should probably solve your problem. Titus "Nihal Ahmad" <nihal@cranessoftware.com> wrote in message news...] = mxCreateDoubleMatrix(1, 1, mxREAL); > ouptr = (int *)mxGetPr(ouhs[0]); > > y = mexCallMATLAB(1,ouhs,0,NULL,"dummyst"); > > single = *ouptr; > If I used to debug the program, the value of single should come 1. > But unfortunatly the value of single is coming to 0 only. > > Any comment will be appreciated. > Nihal Hi Titus, Thank you for immediate response. I checked with double *ouptr, single;, but the problem is same. what to do to sove it. please help me out to solve it. Regards Nihal Titus Edelhofer wrote: > > > Hi Nihal, > without testing your code

Audio problem
Friend has an Evesham (Time/Colosuss/Tiny/Mitac) 8375 laptop with an audio problem -- sound coming only from right-side speaker. Have tried external speakers, headphones and a USB sound 'card' with speakers attached but result always the same. Could it be just the internal speaker itself that's faulty or does it point to a motherboard connector? Either way, how difficult/expensive would it be to put right? TIA In news:20070909-215611.202.0@me.nntp.dsl.pipex.com, Zed typed on Sun, 09 Sep 2007 22:56:11 +0100: > Friend has an Evesham (Time/Colosuss/Tiny/Mitac) 8375 laptop with an > audio problem -- sound coming only from right-side speaker. Have > tried external speakers, headphones and a USB sound 'card' with > speakers attached but result always the same. Could it be just the > internal speaker itself that's faulty or does it point to a > motherboard connector? Either way, how difficult/expensive would it > be to put right? TIA WOW! Did you disable the driver for the internal sound card when you used the USB sound card (through the Device Manager)? And you had to install the USB sound card driver for it too, right? You

problem with synthesis
a test when 'd' is no longer active and after a certain amount of time, led should turn off. Now my code has a precision problem, it does not reliably count high time. I need help to straighten out this code. Where can I get some sample verilog to look at (small modules that implement simple things)? Thanks, module blink(input clk, input d, output reg led); parameter blink_freq = 23; paremeter high_time = 4; // 16 clocks reg ld = 0; reg [blink_freq:0] count; reg [high_time:0] hcount; always @(posedge clk or posedge d) begin if(clk) begin count <= count + 1; hcount <... blink with a frequency clk_freq/(2^blink_freq). > >THere are a couple of problems > >1) I need a module register to hold the signal 'd' when it goes high, >usually 'd' only maintains high for a single clock period. > >2) I need a test when 'd' is no longer active and after a certain amount >of time, led should turn off. Now my code has a precision problem, it >does not reliably count high time. > >I need help to straighten out this code. Where can I get some sample >verilog to look at (small modules that implement simple things

getpwnam problem
; Greetings, > Aaron > -- > Aaron Isotton | http://www.isotton.com/ > You know it's Monday when you wake up and it's Tuesday. -- Garfield But the problem is I always pass the same user(exist in the system) to getpwnam, sometimes it works but sometimes it fails with NULL. Any idea? jholly@cup.hp.com (Jim Hollenback) writes: > ultra (ultraman@rogers_NOSPAM.com) wrote: > : But the problem is I always pass the same user(exist in the system) to > : getpwnam, sometimes it works but sometimes it fails with NULL. Any idea? > > what is the errno when it fails...\n", strerror(errno)); : > else fprintf(stderr, "no such user\n"); : > } : > : But the problem is I always pass the same user(exist in the system) to : getpwnam, sometimes it works but sometimes it fails with NULL. Any idea? what is the errno when it fails? -- Jim Hollenback jholly@cup.hp.com my opinion. "ultra" <ultraman@rogers_NOSPAM.com> writes: >> what is the errno when it fails? > > it didn't set the errno when it failed... > > Huh? What do you mean it didn't set the errno? Here is your original message: > I have

filestream problem
I'm having a little filestream problem. With the code below, I open a file in order to insert its contents into another file. However, right after the opening of the file, insertfile.eof() seems to be TRUE. Before the problematic file is opened, one other file is opened and inserted by the same piece of code (which is in a loop), without any problems. I'm sure that the file to be inserted has several lines of contents, and I also checked if the insertfile stream is closed before opening it. if(FileExists(insertfilepath)) { insertfile.open(insertfilepath.c_str()); while(! insertfile.eof()) { getline(insertfile, insertline); outfile << insertline << endl; } insertfile.close(); } I would really appreciate some advise here. Thanks, Pieter Pieter Provoost wrote: > I'm having a little filestream problem. With the code below, I open a file > in order to insert its contents into another file. However, right after the > opening of the file, insertfile.eof() seems to be TRUE. Before the > problematic file is opened, one other file is opened and inserted by the > same piece of code (which is in a loop), without any problems. I

init.tcl problem
Hi folks, I have a little problem: I embed Tcl/Tk into an application, but there is a nerve-racking init.tcl error, here is the important code: ##### Tcl_FindExecutable(argv[0]); interp = Tcl_CreateInterp(); ... /* * tcl_library */ Tcl_Obj* restcl; Tcl_Obj* libtcl; if (Tcl_Eval(interp, "file join [file normalize $::env(APP_HOME)] tcl lib tcl8.4") != TCL_OK) { return TCL_ERROR; } libtcl = Tcl_GetObjResult(interp); restcl = Tcl_SetVar2Ex(interp, "tcl_library", NULL, libtcl, TCL_GLOBAL_ONLY); /* * Init Tcl/Tk */ if (Tcl_Init(interp) == TCL_ERROR) { return TCL_ERROR; } if (Tk_Init(interp) == TCL_ERROR) { return TCL_ERROR; } /* * Init [incr Tcl/Tk] */ if (Itcl_Init(interp) == TCL_ERROR) { return TCL_ERROR; } if (Itk_Init(interp) == TCL_ERROR) { return TCL_ERROR; } /* * load framework */ if (Tcl_Eval(interp, "source [file join [file normalize$::env(APP_HOME)] scripts init init.tcl]") != TCL_OK) { return TCL_ERROR; } if (Tcl_Eval(interp, "::CreateTopLevel") != TCL_OK) { return TCL_ERROR