Today I'm writing all small or big notes which must be considered in Domino Java development.I was collecting all these from past couple of weeks while doing my project.Hope it helps to others.
Removing unused class from Java Agent |
When you remove any existing class from a Java agent , it doesn't delete from agent class list until you remove from class file.
1- Click "Edit Project".
2- Select class from current agent files and click delete.
Incorporating a Java library with Java agent |
1- Click Edit Project from Java agent programmer's pane.
2- Select Shared Java Libraries.
3- Click "Add/Replace" button to add in agent files list.
Viewing output from a Java agent |
You can review output from a Java agent that is running locally in the Java Debug Console. To activate the console, choose File - Tools - Show Java Debug Console. To clear output from the window, click Clear.
If a Java agent is running on a server, the Java Debug Console output is redirected to a server log file. However sometimes you don't get log.nsf access on production servers.So it's better to incorporate log database with your working database. To log activity in Java code ,you can use my ActivityClass
Important Considerations |
1- Lotus Notes/Domino agents must extend AgentBase and use NotesMain() as the entry point for their functional code.However , In some cases you don't want to use NotesMain() class but you need to use domino classes.Such case you need to pass "Session" object as an argument.E.g; I've an activity logging class which doesn't use NotesMain() method to start.I Just pass "Sesssion" object to access domino methods/properties.
try { Session session = getSession(); AgentContext agentContext = session.getAgentContext(); Database db = agentContext.getCurrentDatabase(); ActivityClass activityLog= new ActivityClass(session); //Process table1 for form1 activityLog.addActivity(session,"Start pushing Form1 to Oracle."); PushOForm1 objForm1= new PushOForm1(session); qs= objForm1.tableUpdater(session); if(qs!="" || qs!=null){ activityLog.endActivity(session,qs); } //Process table2 for form2 activityLog.addActivity(session,"Start pushing Form2 to Oracle."); PushOForm2 objForm2= new PushOForm2(session); qs= objForm2.tableUpdater(session); if(qs!="" || qs!=null){ activityLog.endActivity(session,qs); } activityLog.closeActivity(session); }catch(Exception e) {e.printStackTrace();} |
2- Don't use "System.exit(0)" or "System.exit(1)" to exit, It throws SecurityException. In an application, System.exit may cause corruption problems.
3- Before deploying your Java project on server, make sure you've all permission set in java.policy file on server. You can find details in my previous article
4- To catch Lotus Notes Exception, use NotesException class .E.g,
try { Session session = getSession(); AgentContext agentContext = session.getAgentContext(); Database db = agentContext.getCurrentDatabase(); ActivityClass activityLog= new ActivityClass(session); . . . } // Catch if something wrong happens from Notes side like, Database/view failed to open or invalid formila etc catch(NotesException e) {System.out.println(e.id + " " + e.text);} // Usual Java Exception class catch(Exception e) { e.printStackTrace(); } |
5- Memory management is a consideration for long running programs and programs that create a large number of objects.If you get "Out of memory" error with your Domino-Java code use recycle method.The recycle method unconditionally destroys an object and returns its memory to the system.Java has no knowledge of the heavyweight back-end Domino Objects, only the lightweight Java objects representing them. Garbage collection has no effect on Domino Objects unless you first explicitly recycle them.
The Java Virtual Machine (JVM) starts out at 16MB of heap space and most of it is uncommitted. If the JVM needs more heap than it currently has, it will expand the heap in increments but will not exceed the maximum. Exceptions such as "java.lang.OutOfMemoryError" indicate that a heap has reached its maximum size. You can specify the number of bytes directly or use the suffix "MB" to indicate megabytes, for example, specifying "64MB" is the same as specifying "67108864."
Syntax: JavaMaxHeapSize=number of bytes
6- If you get "Can not find symbol" error in your code, It means something you've not declared and using.This error is similar to "Variable not declared" error in Lotus Script.But in Java this error is not descriptive and clear as Lotus Script.
7- Use NotesFactory class to access domino objects from third party IDE, like Eclipse.
8- At the end never forget to set Java agent security under Programmability Restrictions, fill in "Run unrestricted methods and operations" and "Run restricted LotusScript Java agents" as desired. These fields apply to all programmable interfaces and must be filled in for remote access.
Some weird experience |
1-We can see compilation errors on status bar while compiling Java agent.However sometimes I don't see any message, It doesn't matter how many times I click on "Compile All". Afterwards no change in Java code gets effect, I must need to re-start my Notes to fix this. Still it's happening :(
2-If by any chance my Notes gets crash, next time when I try to run my Java agent ; It throws "Class not found" exception . I need to edit and re-save my agent to make it work.
3-Sometimes when I do some changes in my agent, recompile and save the code and runs to see the output, I noticed it doesn't show results with updated code. It doesn't matter if I save with ctrl+s or using tool bar. I need to close my agent, then it asks me to save and I say yes to see the updated output.
I don't know if anyone else is facing this issues with 8.0(basic) IDE.
Some good IBM articles ,
# Using Lotus Notes with Eclipse to manage and run your Java programs
# Java access to the Domino Objects, Part 1
# Java access to the Domino Objects, Part 2
# Connecting Domino to the Enterprise Using
# Learning the Java Language
July 10, 2009 at 2:07 AM
Really good article, very helpful, learnt something new today
July 10, 2009 at 9:54 AM
Its really good, that someone takes the work.
But its not-evil-intended-nitpicking friday again.
A great boost in productivity with Java development for notes at least for me, is buried in the "Using Lotus Notes with Eclipse to manage and run your Java programs". With the box under point 3, we can import your .java, .properties, .xml, etc files directly from the source folders in Eclipse. Its described in the article "Using Lotus..." linked in your article. But it may be overlooked. Me and some of the folks I've shown Java dev in Notes found it really important.
Ones used to it, I only type anything in this notes java editor.
May 18, 2010 at 1:36 AM
good article..very useful for me..
http://ps-otomotif.gunadarma.ac.id