anix
anix

Reputation: 345

Unable to access Resource file in Lotus Notes Java Agent

I am facing issue accessing files imported to the resource section of Lotus Notes Java Agent (Content Section).

I am trying the bellow code

getClass().getClassLoader().getResource("gift.png").getPath() 

but it return null every time this resource is located inside Res/gift.png ( Res is a folder in Lotus Java Agent )

i have also tried

InputStream is = JavaAgent.class.getClassLoader().getResourceAsStream("gift.png");

this too returns null...

i could not find much source on lotus java agent so tried some regular java code. does anyone faced similar issue. or their is some other method or way to access resource file in Lotus Java Agent

Upvotes: 4

Views: 4342

Answers (3)

stwissel
stwissel

Reputation: 20384

You would want to: 1) Not use JavaAgent, but one of your own classes that you use in the agent 2) use this.getClass().getResourceAsStream("/gift.png"); 3) it is / not \ even on Windows. 4) you need to start with a / to ensure you start at the agent root Hth :-) stw

Update: the "/" is equivalent to the src (or compiled bin) folder but the res folder is copied into the root of the compiled agent. So cut out the /res part. Alternative create your own folder inside the src folder. Easiest way is to open the agent for edit and then use the navigator on this temp project.

Upvotes: 3

Jesse Gallagher
Jesse Gallagher

Reputation: 4471

I just tried making a quick test agent containing one imported resource named "email.html". Inside of NotesMain() in the main JavaAgent class, I was able to do this to read the content, so this may be the way to go:

InputStream res = this.getClass().getResourceAsStream("/email.html");

So the upshot is: apparently leave out the "res" bit entirely.

Upvotes: 1

D.Bugger
D.Bugger

Reputation: 2359

Res is a folder in an agent?? Never heard of.

Try with a normal resource name, without the "Res\", or try "Res\gift.png"

It could also be a security problem, see here 1

Upvotes: 0

Related Questions