Earlier today I say a tweet from Fredrik Norling about a blog post he did in 2014 for copying and pasting Java code between XPages and Java agents.
— Fredrik Norling (@XPageDeveloper) 15 December 2016
It reminded me of something I noticed a while ago. I think it was when I was looking at the On Disk Project for an NSF while I was editing a Java agent or Script Library.
Because I started working with Java in XPages in 8.5.1, I’ve always done the standard web development approach of creating a source folder (typically WebContent\WEB-INF\src) and putting my Java code as normal Java classes in there via the Package Explorer view. So I’m used to spending time in the Package Explorer view.
When you edit an Agent or Script Library via the standard interface, you get a UI like below. This is an agent with a single Java class, but also using a Java Script Library (OpenLog). This is useful for editing, but doesn’t make it easy to copy the classes if you want to re-use them in XPages or copy classes from XPages to an agent.
But something interesting happens if you look at Package Explorer (note, you’ll need to deselect working sets). When you open the agent, it creates a project in Package Explorer for the Java Agent and for any Java Script Library incorporated into it, as below.
As is standard in Java development, it has a “src” folder that contains the classes (admittedly not in a properly named package), along with all the relevant project settings (any Java jars on the build path etc). Save and close the agent, and the project will disappear. They’re basically loaded temporarily, prefixed with the NSF name. The same happens for a Java Web Service. This then allows you to copy a whole Java class – or bunch of Java classes – quickly and easily to move them around.