Hi
I have quite a lot of experience with exactly this issue...
--> You cannot use a jar-file added to your project to be used with XPages in a Java agent. The agent runs in its own JVM (i.e. different class loader).
I have discussed this with a few IBM'ers, including Steve Nikopoulos, Stephan Wissel, and Maureen Leeland. I have tried to implement my own class loader to be able to load the jar-file in the agent (or a webservice - which has the same limitations) - but without success.
I would also like to do this for other reasons than sharing the jar-file between XPages and agents - e.g. for easy deployment through the ntf-file.
So what are your options?
1. Add the jar-file to your agent
However, there is a memory leak in the function that detaches (automatically) the jar-file before using it in the agent. It will make your jvm crash. This is true for agents and webservices. It does not matter whether you attach the jar-file to the agent/webservice itself or a Java Library that you then include. I have verified this as a problem in versions 7.02 to 8.5.2 (on SuSE Linux and Windows).
2. Add the jar-file to the jvm/lib/ext directory
This works fine - it just needs the jvm to be restarted one time after the jar-file is added. This can be a pain for Java code called by Notes clients. And it does take a few more steps when deploying on servers... But it runs stable and fast :-)
3. Rethink your agent to an "XAgent"
An "XAgent" is an XPage which does not render any output. It can access the resources as you already do. You could then call this "XAgent" through a url. It depends on your application's logic whether this is an option for your.
/John