4

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

anix
  • 347
  • 4
  • 14

3 Answers3

3

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.

Josh Jolly
  • 11,258
  • 2
  • 39
  • 55
stwissel
  • 20,110
  • 6
  • 54
  • 101
  • Hi Stw, i have already tried all the 4 method before posting the query, some how no luck ... or may b i am doing something wrong – anix Mar 30 '12 at 14:18
  • Wrap all that is not the Java agent itself into a Jar that you import and try again – stwissel Mar 30 '12 at 22:39
  • hi stw, i tried making a jar file, it still don't work with Java Agent. but it works for simple java program using eclipse ... :( – anix Apr 02 '12 at 08:37
  • You could keep your resources inside the src folder (can be a subfolder) - initial answer above updated. – stwissel Apr 02 '12 at 12:54
  • hi stw, thanks for that, it worked for me `getResourceAsStream("/gift.png")` which was ok , but issue still comes for `gerResource("/gift.png").getPath()` it returns null pointer exception.... but i can live with InputStream for now.. – anix Apr 04 '12 at 06:34
  • it doesn't have a Path since it is inside an NSF. – stwissel Apr 04 '12 at 14:17
1

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.

Jesse Gallagher
  • 4,461
  • 13
  • 11
0

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

Community
  • 1
  • 1
D.Bugger
  • 2,300
  • 15
  • 19
  • `Res is a folder in an agent??` - I mean when you create a New Java Agent, you have Res and Archive section/folder in the agent section (like eclipse projects) to added new resources or jar files. – anix Mar 30 '12 at 14:18