More Related Content


More from panagenda(20)


Connect2014 Show104: Practical Java

  1. SHOW104: 
 Practical Java Mark Myers, London Developer Coop Julian Robichaux, panagenda © 2014 IBM Corporation
  2. Who Are These Lovely Speakers? ▪ Mark Myers – Member of the London Developer Co-op (, a group of UK based developers – Developer from a support background – 12+ years on Domino, 15+ years in IT – Speaker at 4x Lotuspheres, 4x UKLUGs, 1x ILUG, 1x BLUG Here I am refusing to take my zombie escape practice seriously
  3. Who Are These Lovely Speakers? ▪ Julian Robichaux – Developer at panagenda, an Austrian based 
 IT management software provider – Purveyor of – Writer of open-source (and commercial) software – 2014 IBM Champion – Speaker at Lotusphere since 2006, many LUGs 
 and View conferences in various countries Dangerous pedestrians 
 in these parts. Beware!
  4. Why Are We Here? ▪ To show you practical tips and tricks when dealing with the wider world of Java ▪ To save you from a steep learning curve on learning practical Java particularly where it comes to developing for the IBM® stack ▪ Help you move your brain into the WebSphere® / Connections™ mind set for providing solutions – If you want to provide more than basic customizations to Connections™ then you need to learn WebSphere (sorry about that). ▪ And to protect that brain from brain eating zombies (grrrrr)
 ▪ NOTE: Some of the WebSphere / Connections stuff might seem esoteric if you’re a Domino Developer, but someday you’ll need it…
  5. What Technology Was Used? ▪ Oracle® Java™ and IBM® Java™ (some manner of version 1.6) ▪ IBM (Lotus) Notes® 9.0 ▪ IBM WebSphere® v8 (minimum v8.0.0.5 plus hot fixes for IBM Connections™) ▪ IBM Rational® Application Developer for WebSphere Software v9.0.0 ▪ Eclipse™ Java EE IDE for Web Developers (Kepler for WebSphere, Ganymede for plugins) ▪ Spring Tool Suite v3.4.0 ▪ NetBeans™ IDE 7.4 ▪ IntelliJ™ IDEA Community Edition 13.0.1 ▪ IntelliJ IDEA Ultimate Edition 13.0.1
  6. Relational Data Access 6
  7. Connection to Relational Databases ▪ When we started writing applications for Connections rather than Domino we went from the easy going world of Document based storage and constantly being able to ask for the current database to the wild world of Relational databases and defining our own contexts (most likely DB2) ▪ There are lots of different ways of linking your applications to databases (in Java) but the nearly all of the popular ones are based around a library called “Hibernate” http:// ▪ Hibernate is an Object/Relational Mapper or “ORM” , which basically means it does the hard work of mapping the items in a relational database such as a table and fields to the Objects that you use in Java such as classes and fields.
  8. Connection to Relational Databases – Mapping Databases to Java
  9. Connection to Relational Databases ▪ To communicate with hibernate we are going to use JPA or Java Persistence API which gives us – Expanded object-relational mapping functionality (over what hibernate normally gives us) – support for collections of embedded objects, linked in the ORM with a manyto-one relationship – multiple levels of embedded objects – ordered lists – combinations of access types – A criteria query API – support for validation
  10. JDBC Basics ▪ But why use such an extra Layer, why not just write SQL statements? ▪ Using such a persistence layer gives us some advantages over direct SQL commands – Eliminates all of the 'hand' mapping in Java from a SQL ResultSet to a Java Object greatly reducing the amount of mapping work – Avoids low level JDBC and SQL code: you just deal with Java Classes – Provides high end performance features such as caching and sophisticated database and query optimizations – Allows you to do things like change your back end db or insert connection pool management ( without recoding your app ▪ There is lots of fighting over if you should use an ORM (Object-relational mapping) framework such as JPA, but frankly it’s quick, reliable, and does not give you grief
  11. JDBC Setup – Relational Databases ▪ Relational Database Connections are normally not direct. JDBC config on Server Entity Manager used code to do stuff JDBC Mapped to Persistence unit In Persistence.xml Entity Manager Calls Entity Manager Persistence Unit used by Entity Manager helper
  12. Connection to Relational Databases ▪ Connections and WebSphere apps normally do not define their JDBC inside the app, they ask the server to provide one under a given name ▪ Pros – Protects the developer as all database administration is handled by the administration team (hard to get blamed) – You don’t need to know any passwords, so you have the same deployment from dev through to live ▪ Cons – Debugging rights issues and other issues is often harder – A change can be made that impacts your Application without you knowing what ▪ Let’s connect to a DB2 instance on a WebSphere (Connections) server…
  13. JDBC Setup – Server Side ▪ Your JDBC connections are setup on the WAS server normally by your Admin This actually provides the link to the database and you don’t need to deal with Authentication
  14. JDBC Setup – Server Side WebSphere Admin Console ▪ If want to set up a JDBC connection to a DB2 server on WebSphere ▪ First open up the WAS admin console, and select “JDBC Providers”
  15. JDBC Setup – Server Side ▪ You will need 2 driver files – “db2jcc.jar” – “db2jcc_license_cu.jar” ▪ Are on the server? They should be if Connections is on there.
  16. JDBC Setup – Server Side Environment Variables ▪ You can Check the location in “Environment” ! “WebSphere Variables” ▪ If they are not present, either copy them there or ask your admin
  17. JDBC Setup – Server Side New authentication profile ▪ First we want to set up the authentication for the JDBC as if you don’t it will drop out of the JDBC setup wizard and you will have to do it again. ▪ Go to “Resources” ! “JDBC” ! “JDBC providers” ! “profilesJDBC” ! “Data sources” ! “profiles” ! “JAAS” ! “J2C authentication data” ▪ Click “New”
  18. JDBC Setup – Server Side New authentication profile ▪ Fill in the User name and Password of the account that has the rights to the database that you require as well as an alias for it to be know as on WebSphere ▪ Click “Apply” ▪ Then when prompted click “Save”
  19. JDBC Setup – Server Side New authentication profile ▪ We now have a new Authentication profile
  20. JDBC Setup – Server Side New data source ▪ Now Under “Resources” ! JDBC ! “Data Sources” , select a Scope (Normally just the top “Cell” level) ▪ Click “New”
  21. JDBC Setup – Server Side New data source ▪ Enter a human readable “Data Source Name” ▪ And a unique “JNDI Name”. Ensure you put “jdbc/” before this name and avoid spaces and special characters ▪ Click Next
  22. JDBC Setup – Server Side New data source ▪ If you have already connected to another data source on this server using the same account details, then you can select from an existing JDBC provider, otherwise select “Create new JDBC provider” ▪ Click Next
  23. JDBC Setup – Server Side New data source ▪ We will assume that it is a DB2 database you are connecting to (nearly all Connections servers are run on these) ▪ Select “DB2 Universal JDBC Driver Provider” and “Connection pool data source” ▪ Click “Next”
  24. JDBC Setup – Server Side New data source ▪ As long as the 2 jar driver files we checked before are listed on in the class path box, you can just click “next”
  25. JDBC Setup – Server Side New data source ▪ Stipulate the name of the database you want to connect to, and its server ▪ Port Number is normally the same for each server type, for DB2 it is 50000 ▪ Click “Next”
  26. JDBC Setup – Server Side New data source ▪ Now you will be asked for the security alias you created before ▪ Select them from the drop down ▪ Click Next
  27. JDBC Setup – Server Side New data source ▪ Review the summary and if you are happy, click “Next” , then “Save”
  28. JDBC Setup – Server Side ▪ You now have a new JNDI you can use in your code
  29. Now we have a database connection – What Next? ▪ Time to glue our server database connection to code so we can finally do something useful ▪ We are starting with a pre-created Java web project (here is one we created earlier) ▪ If you want to know how to make one of those come to: – SHOW303: Proper Connections Development for Proper IBM Domino Developers • Tuesday | 10:30-12:15 | Swan Osprey • Matt White & Mark Myers, London Developer Coop
  30. JDBC Setup – Code – Persistence.xml ▪ First up you will want somewhere for the JNDI you have just setup to live in your application. ▪ This place is the persistence.xml, this is a XML document placed in the “META-INF” directory in your source directory ▪ In this file we will create a “Persistence Unit” configuration
  31. JDBC Setup – Code – Persistence.xml This is the persistence unit name, Remember this When dealing with WebSphere the transaction- name as you will want it latter type will always be “RESOURCE_LOCAL” Here is the JNDI name you have just setup These are the java classes that you want to map to tables in the database
  32. JDBC Setup – Code ▪ Now we have a Persistence unit (which tells us which classes we want to glue to the JDBC setup on WebSphere) we want a helper unit to look after that for us ▪ This is a just a normal Java file that is best to put in the same place as the rest of your Object classes (well in truth the wizard will put it there for you)
  33. JDBC Setup – Code Here is the persistence unit name from the persistence.xml
  34. JDBC Setup – Code ▪ We can now create a Data Access Object file to go with our actual “Employee” (we will show you these being made via a wizard in few slides) ▪ This will hold all the functions we will use to actually access the data for the “Employee” table
  35. JDBC Setup – Code Here we call the EntityManager from earlier Table/Class Data Access Object
  36. JDBC Setup – Code ▪ Now lets finally create a normal java class to use all of this.
  37. JDBC Setup – Code Finally use the data in code Here we are using the “findbyProfGuid” function which is a auto generated function a bit like get the Domino function Getalldocumentsbykey this will give us a list of matching employees
  38. JDBC Setup – Code - Demo Don’t worry this is all done with wizards (in most IDE’s), let us show you 38
  39. JDBC Setup – Code – Demo
  40. A Note About Non-Relational Databases ▪ Before we wrap up relational databases and leave you thinking the world has just got more complicated, there is a bit of good news ▪ Although the default for most of the programming world, relational database usage has its limitations, it is not very good for “big data” and finds it hard to scale to handle distributed updates, quite a few modern web applications have moved away from it eg. Facebook and twitter ▪ What have they moved to?? – They have moved to “NoSQL” a form of database that uses a document format that has multiple nodes scattered all over the place and that replicate to keep each other up to date…. Does this sound familiar??
  41. A Note About Non-Relational Databases ▪ Domino is classed as a “NoSQL” database, ☺ ▪ YOU already have the background and knowledge to excel in this, and have though years of experience got a handle on concepts that many Java developers are struggling with (having only known Relational databases) ▪ With knowledge of both types of Database you can make far better decisions on which is suitable for a given solution. ▪ Further Reading (The competitors) – CouchDB ( ) – SimpleDB ( ) – MongoDB ( )
  42. Parsing Connections Feeds ▪ Of course, the Connections API is geared towards using Atom feeds for data access (not JDBC directly) ▪ If you want to fetch and parse the feeds, the Apache Abdera Java library is an excellent choice – – Handles HTTP connections and authentication as well as parsing ▪ There are also some nice wrappers around the API/feeds in the Social Business Toolkit – – See AD301: What's New on the IBM Social Business Toolkit later this week
  43. Connections Feeds – Apache Abdera Example ▪ Quick example using Apache Abdera ▪ Java agent in a Notes database ▪ You will need these JAR files attached to the agent – Or in the ext folder • Best option for performance, if you can 
 do it – Or a script library • DANGER: in some versions of Domino, 
 attaching large JAR files to a script library 
 and calling them from agents on a regular 
 basis can use excessive memory ▪ Agent code on the next two slides
  44. Connections Feeds – Apache Abdera Example
  45. Connections Feeds – Apache Abdera Example
  46. Data Analysis ▪ So you’ve retrieved a bunch of data. Now what? ▪ The most popular data analysis tool still seems to be… spreadsheets ▪ Apache POI is a great library for generating Excel compatible spreadsheet files – Formats: XLS, XLSX, DOC, DOCX, PPT, PPTX – ▪ Nice thing about spreadsheets is that you just compile the data, the end-user can do whatever “stuff” they want with it – Pivot tables, sorting and filtering, etc.
  47. Apache POI Example
  48. Apache POI Example
  49. Data Analysis ▪ What if you have to do the “stuff” for the user? ▪ Need to generate a report? – Apache POI (just make a fancy spreadsheet) – BiRT – ▪ Need to make some graphs and charts? – BiRT might have what you need – jFreeChart – ▪ Need to do some heavy number crunching? – FreeHEP (HEP = High Energy Physics) – – SCaVis (formerly jHepWork) – from
  50. Images, PDFs, and Plugins and Notes and Eclipse too! 50
  51. Lotus Expeditor ▪ The Eclipse-based Notes client is built on top of Lotus Expeditor, which is built on top of Eclipse ▪ To create a plugin for the Notes client, you need Eclipse and the Lotus Expeditor Toolkit – And, to do it strictly by the book, Windows ▪ Free downloads – – ▪ Good list of steps and other information in this wiki article: – Getting_started_with_the_Lotus_Expeditor_Toolkit_6.2.1 – (or just look at the next few slides)
  52. Installing Eclipse ▪ For the Expeditor Toolkit version 6.2.x: – Download and install Sun Java 1.6 JDK • – Download Eclipse for RCP Plugin Developers, version 3.4 (Ganymede) • – Unzip the Eclipse ZIP file using 7-Zip or a similar tool ( ) • Do NOT use native Windows unzip – it is very slow and sometimes chokes on long filenames • Unzip to a small, sensible folder. Like c:javaeclipse or c:eclipse • All done, Eclipse is now installed! – Download the Expeditor Toolkit • • Unzip the file with 7-Zip or similar to a short path (like c:temp) • Open Eclipse by double-clicking eclipse.exe and follow the steps on the next few slides
  53. Installing the Expeditor Toolkit in Eclipse ▪ Choose the menu option Help > Software Updates… • There is a slightly different process on newer versions of Eclipse, but you’re using 3.4, right?
  54. Installing the Expeditor Toolkit in Eclipse
  55. Installing the Expeditor Toolkit in Eclipse Required Optional
  56. Creating A Plugin Project ▪ After you install the Toolkit, 
 when you create a new 
 workspace in Eclipse you will 
 see an Expeditor Configuration 
 dialog ▪ Use these settings
  57. Creating A Plugin Project ▪ From the splash screen, choose the 
 menu option File > New > Project ▪ Choose Plug-in Project from the list 
 and click “Next” ▪ If Plug-in Project is not available, 
 you installed the wrong version of 
 Eclipse (you need an RCP developer 
  58. Creating A Plugin Project ▪ Create a project name, then click “Next” to accept the defaults on the next two screens
  59. Creating A Plugin Project ▪ To make this a little easier, choose the 
 “Hello World Command” template, which 
 is already set up to create a menu item 
 with an action handler class for the menu ▪ Then click “Finish” ▪ You will be asked to switch to the plugin 
 perspective. What a great idea. Click “Yes”.
  60. Creating A Plugin Project
  61. Accessing An Image ▪ This plugin will use the computer’s webcam to capture a picture of the user ▪ We will use the sarxos Webcam Capture Java library – – Built-in native drivers for Windows, Mac, and Linux (and Raspberry Pi) – MIT open-source license ▪ I had to make a slight modification to the code to keep it from crashing the Notes client – Also had to use a different version of the bridj JNI library to access the native/DLL webcam drivers (version 0.6.2: ) – Notes is special! ▪ Another caveat: if your webcam connects and disconnects repeatedly, this can also cause problems – Buyer beware, use at your own risk, add lots of error handling, etc.
  62. SIDEBAR: Using a Mac Webcam from VMWare Fusion ▪ Lots of developers use Macs and MacBooks these days – And VMWare Fusion because, you know, Domino Designer… ▪ If you try to access a Mac webcam from VMWare Fusion, you get this message:
  63. SIDEBAR: Installing the BootCamp Drivers ▪ The easiest way to install the Bootcamp drivers into VMWare Fusion is to use the Boot Camp Assistant app, which should already be in your Applications folder
  64. SIDEBAR: Installing the BootCamp Drivers
  65. SIDEBAR: Installing the BootCamp Drivers
  66. SIDEBAR: Installing the BootCamp Drivers ▪ If you have trouble burning the CD (or need to do it again), the disc image is at: 
 /Library/Application Support/BootCamp/WindowsSupport.dmg ▪ You can also use the DMG file directly as a CD Disc Image in VMWare Fusion
  67. SIDEBAR: Installing the BootCamp Drivers ▪ Access the CD (or disc image (or files)) from your Windows VM and run setup.exe ▪ After you do the install, restart your Windows VM ▪ Also a good idea to disable any new Apple services that were installed (you don’t need them for a VM) ▪ The newer (version 4+) BootCamp drivers work with Windows 7 and higher – If you have a Windows XP VM, use the version 3.0 drivers from a Snow Leopard install disc ▪ Driver updates are available at: –
  68. Using the Sarxos Java Webcam Library
 adding the files to the project ▪ Download the latest “dist” zip file from – I started with • See the References slide for where to download my 
 modified JAR file for this project ▪ Create a new “lib” folder in your plugin project – Right-click the top-level project name in the sidebar, 
 choose New > Folder ▪ Drag the following files from the webcam-capture download 
 to the new lib folder: – webcam-capture-0.3.10-LS14.jar – bridj-0.6.2.jar – slf4j-api-1.7.2.jar
  69. Using the Sarxos Java Webcam Library
 setting the build path ▪ Right-click the “lib” folder and 
 choose Build Path > Configure 
 Build Path ▪ Add the webcam library files 
 to the Libraries tab in the 
 Build Path dialog ▪ Alternatively, you can right-click 
 the files in the folder and choose 
 “Add to Build Path”
  70. Using the Sarxos Java Webcam Library
 adding the files to the binary build ▪ Double-click the plugin.xml entry in the plugin sidebar, go to the “build” tab, and make sure the new “lib” folder and all the files in it are checked for the “Binary Build”
  71. Using the Sarxos Java Webcam Library
 setting the classpath ▪ Go to the “Runtime” tab and add all the webcam jar files to the Classpath – Use the “Add…” button!
  72. Using the Sarxos Java Webcam Library
 custom JDialog class ▪ The sarxos webcam library has a custom JPanel that can display a live webcam feed – This means we will have to use Swing to display and use it – We will create a custom JDialog to display the panel and return a snapshot image
  73. Using the Sarxos Java Webcam Library
 custom JDialog class (constructor)
  74. Using the Sarxos Java Webcam Library
 custom JDialog class (constructor)
  75. Using the Sarxos Java Webcam Library
 custom JDialog class (constructor)
  76. Using the Sarxos Java Webcam Library
 custom JDialog class (webcam start thread)
  77. Using the Sarxos Java Webcam Library
 custom JDialog class (take a snapshot action)
  78. Using the Sarxos Java Webcam Library
 custom JDialog class (save snapshot action)
  79. Using the Sarxos Java Webcam Library
 calling the dialog from the toolbar action
  80. Using the Sarxos Java Webcam Library
 let’s see this baby work
  81. Cropping And Resizing The Image ▪ First you want to get your image as a BufferedImage – for File, InputStream, or URL – Webcam returned a BufferedImage directly ▪ Cropping is just a matter of using BufferedImage.getSubimage(x, y, width, height) – This returns a new BufferedImage ▪ Resizing requires a little more work, because changing image size also affects image quality
  82. Resize Option #1
 AffineTransform ▪ AffineTransform is an easy way to resize ▪ Resizing based on a scaling factor, where 0.75 means shrink to 75%, 1.25 means enlarge to 125%, etc. ▪ Scaling types are TYPE_NEAREST_NEIGHBOR, TYPE_BICUBIC, TYPE_BILINEAR, or null – See AffineTransformOp op = new AffineTransformOp (AffineTransform.getScaleInstance(scale, scale), AffineTransformOp.TYPE_BICUBIC); bi = op.filter(bi, null);
  83. Resize Option #2
 getScaledInstance() ▪ Use BufferedImage.getScaledInstance(width, height, renderingHint) ▪ Rendering hints define the algorithm to use for resizing, which affects quality – Image.SCALE_DEFAULT – Image.SCALE_FAST – Image.SCALE_SMOOTH – Image.SCALE_REPLICATE – Image.SCALE_AREA_AVERAGING ▪ SCALE_AREA_AVERAGING works fairly well ▪ Unfortunately, getScaledInstance() returns an Image, not a BufferedImage – This requires a few extra lines of code…
  84. Resize Option #2
 getScaledInstance() Image tempImage = oldBufferedImage.getScaledInstance(width, height, Image.SCALE_AREA_AVERAGING); ! BufferedImage bi = new BufferedImage(tempImage.getWidth(null), tempImage.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.drawImage(tempImage, 0, 0, null); g.dispose(); ! tempImage = null;
  85. Resize Option #3
 gradual resize ▪ Draw the image to a java.awt.Graphics2D instance using java.awt.RenderingHints – Full list of hints at RenderingHints.html – RenderingHints.VALUE_INTERPOLATION_BICUBIC is good for photos ▪ If the size shrinks or grows more than 50%, keep growing or shrinking by 50% as many times as needed ▪ Excellent discussion of this technique (and about image resizing in general) at: https:// ▪ Generally much better image quality than getScaledInstance
  86. Resize Option #3
 gradual resize do { ! if (w > targetWidth) { w = (int)Math.max(w / 2, targetWidth); h = (int)Math.max(h / 2, targetHeight); } else { w = (int)Math.min(w * 1.5, targetWidth); h = (int)Math.min(h * 1.5, targetHeight); } BufferedImage tmp = new BufferedImage(w, h, type); Graphics2D g2 = tmp.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint); g2.drawImage(ret, 0, 0, w, h, null); g2.dispose(); ret = tmp; } while (w != targetWidth || h != targetHeight);
  87. Resize Comparison Examples AffineTransform getScaledInstance Gradual resize 90px 45px
  88. Get Some User Information ▪ Next we will get some information about the user to go along with the picture ▪ Since this is a Notes client plugin, we will do a lookup in the Domino Directory ▪ The process: – Use session.getAddressBooks() to find a public 
 address book – Look up the user’s Person doc – Get the fields you’re interested in ▪ LDAP lookup is an exercise left to the reader
  89. Accessing the Notes API From A Plugin ▪ To access IBM Notes from a plugin, use a NotesSessionJob – You can do almost anything you’d be able to do from a Java agent – “Current Database” isn’t available, like it would be from an agent – In Notes 8.0, you use NotesJob instead and instantiate your own session ▪ Runs asynchronously by default – Subclass of an Eclipse Job, which is like a thread ▪ Getting information back: – Use listeners (preferred) – Use join() to wait for job to finish (not as good)
  90. General NotesSessionJob Code Structure
  91. Getting User Information ▪ We can get the user name directly from the Notes session ▪ We will lookup other user information from the public Address Book
  92. Getting User Information
  93. Getting User Information
  94. Stick It All in a PDF ▪ Finally, we will put the picture and 
 the user info into a PDF for distribution
  95. Java PDF Libraries ▪ Several to choose from: – Apache FOP – Apache PDFBox – PDFJet – iText – Many others... ▪ Always check the license ▪ Lowagie iText is an excellent option – Initial release in 1999 – Currently on version 5.x (although it jumped from 2.1.7 to 5.0.0 in 2009) – Open-source licensed as AGPL in version 5.0, dual-licensed as MPL/LGPL for version 2.x, commercial licenses available –
  96. Options for Creating PDFs in iText ▪ Generate the PDF from scratch – Create a PDF doc in memory – Add formatting, paragraphs, images, etc. – Save to a file – Examples at ▪ Use an existing PDF as a template – Interesting technique described by Jake Howlett ( – Create a template doc in OpenOffice or Word or whatever, and save to a PDF – Open the PDF template file in iText – Add paragraphs, images, etc. as above – Save to a file – Good examples and advice at samplechapter6.pdf
  97. Add the iText JAR to the Eclipse Project ▪ Same process as with the webcam jar files – Import (or drag) to the “lib” folder – Add to the build path – Add to the classpath – Make sure the file gets included in 
 the binary build
  98. Simple Wrapper Class for PDF Creation
  99. Simple Wrapper Class for PDF Creation
  100. Simple Wrapper Class for PDF Creation
  101. Simple Wrapper Class for PDF Creation
  102. Putting It All Together ▪ All the heavy-lifting code was put in wrapper classes for ease of use (and reusability) ▪ We call it from the action handler class that gets called when the menu is triggered
  103. Putting It All Together
  104. Putting It All Together
  105. Tips, Tricks, and Gotchas ▪ Plugins can crash the Notes client – Be very careful, code defensively – They can also cause the client to appear unresponsive if things run in the UI thread ▪ The webcam library can, in certain circumstances, crash the Notes client – Use the specific JAR files we mention here ▪ Java Swing and SWT don’t always play well together – index.html ▪ Examples and info on extending the Notes menus and toolbar – ▪ Example of adding a PDF directly to a Notes document without writing to the file system: – (our Lotusphere 2012 session)
  106. Other IDEs Checking out the competition 106
  107. Other IDEs We Might Want To Use ▪ As Domino developers you have always developed with Domino Designer given Notes/ Domino proprietary nature. ▪ As a Connections developer you have far more options at your disposal. All with their pros and cons. ▪ The Java zombies are also very aggressive so you need to have at least evaluated the alternatives or they will try to eat brains ▪ There are 3 Main Contenders – Eclipse ( – NetBeans ( – Intellij IDEA ( ▪ For each of these we will go through the process of integrating WebSphere into the IDE and building a basic web site deployed via an Ear file
  108. Where you develop – Core Eclipse ▪ Eclipse is the default and most common Java IDE, particularly so in the IBM world as it was originally written by IBM (it came from the Visual age codebase) and released into open source in 2001 ▪ Except for a core runtime, everything is a plugin with eclipse, ▪ Primarily used for Java, but plugins available for tons of languages including: – C, C++, COBOL, Fortran, Perl, PHP, Python, R, Ruby / Ruby on Rails, Scala, Clojure, Groovy, Scheme, and Erlang.
  109. Where you develop – Core Eclipse ▪ Pros – Thousands of plugins – Widely supported – Custom Builds. ! • One of the main advantages of Eclipse is its ability be completely skinned and rebadged (see following slides) • With enough effort you can build your own custom build with plugins for free ▪ Cons – Easy to get bloated – Due to its age and versatility, not as dynamic or fast as competitors – Versioning and upgrades often cause plugins to break and it’s tricky to do full compatibility tests
  110. Where you develop – Eclipse Custom Builds ▪ Some of the popular ones are – Domino Designer (we think you know this one) – Scala ( – Adobe Flash Builder ( – Spring Tool Suite ( ! ▪ Nearly all of these have eclipse plugins alternatives – Plugins allow you to keep your existing setup, but are often not as seamless a experience as a dedicated custom build, – Consider installing multiple custom builds for specific projects as a more stable alternative to overloading one Eclipse IDE
  111. Where you develop – IBM Rational Application Studio Eclipse Build ▪ IBM Rational Application Developer for WebSphere Software is the current enterprise application offering from IBM ( ▪ Pros – Excellent integration with WebSphere – Official nature useful in preventing “buck passing” on WebSphere/ Connections support issues – Universal Installer allows full installation of all parts of IDE (servers, etc) – Geared to Enterprise developer on a corporate network ▪ Cons – Expensive – Managed by License server • makes prolonged disconnect from network tricky, but does allow license sharing – Geared to Enterprise developer on a corporate network
  112. Where you develop – Genuitec MyEclipse Blue Eclipse build ▪ MyEclipse Blue Edition is a direct competitor to IBM’s Rational Application Developer ( ▪ Pros – Reasonable price – Very feature rich – Fast ▪ Cons – Constant prompting to upgrade can lead to having tool versions incompatible with existing deployments (a particular issue for Connections developers) – Does not come with WebSphere, DB2, etc.; these need to be installed separately.
  113. Bit of background - What are WAR and EAR files ▪ A .War file (Web application ARchive) is a file used to distribute a collection of Java Server Pages, Java Servlets, Java classes, XML files, tag libraries, static Web pages (HTML and related files) and other resources that together constitute a Web application. ▪ An .Ear (Enterprise ARchive) is Basically a normal War file wrapped in a configuration wrapper. ▪ The Configuration wrapper of the Ear file contains features that while are very useful and powerful for WebSphere applications (adding JDBC connections on install, etc) are dangerous on a Connections server – remember you are on a shared server and you can not make any assumptions as to what is happening – After working with multiple Connections administrators, the general opinion is to document the features you require and ask your administrators to manually add them rather than use the Ear file
  114. Setting up Eclipse for WebSphere ▪ If you are not using an Eclipse instance built for WebSphere development you will need to download the “IBM WebSphere Developer Tools for Eclipse” from the Eclipse Marketplace – You can reach this via the “Help” ! “Eclipse Marketplace” and search for WebSphere ▪ Remember that if you are developing for Connections 4 or 4.5 you will want WebSphere V8 not V8.5
  115. Setting up Eclipse for WebSphere ▪ Once the plugin is installed you can go to the Servers Tab (nearly always at the bottom of the screen), right click and select “New” ! “Server”
  116. Setting up Eclipse for WebSphere ▪ You can now select the WebSphere server v8.0 option. ▪ Click Next
  117. Setting up Eclipse for WebSphere ▪ Select the Server location and which Profile you want to use ▪ Click Finish Tip: try to get used to having security turned on, as if developing on a Connections server ALL security is turned on
  118. Setting up Eclipse for WebSphere - Gotcha 1 ▪ WebSphere is NOT under “Download additional server adaptors” on the server Definition wizard
  119. Setting up Eclipse for WebSphere - Gotcha 2 ▪ If you are Installing IBM Rational application developer you have to select the plugin then rather than later as per normal Eclipse
  120. Eclipse Showroom Demo
  121. Where you develop – NetBeans ▪ The Longtime Alternative to Eclipse, developed independently and now owned by Oracle ▪ Pros – The best native Java integration – Free ▪ Cons – Strong slant to Oracle’s own products and platforms (Glassfish, etc) – No integration for WebSphere proper • There is a community plugin for WebSphere community edition ( plugin/40546/wasce-plugin) • And an Ant script work around ( – Less 3rd party support than competitors
  122. Building an Ear file in NetBeans ▪ Click “File” ! “New Project” ▪ Select “Java EE” ! “Enterprise Application” ▪ Click Next
  123. Building an Ear file in NetBeans ▪ Give your Application a Name and a Location ▪ Click Next
  124. Building an Ear file in NetBeans ▪ As there is no WebSphere integration select “Glassfish Server” ▪ Ensure you Select “Create Web Application Module”
  125. Building an Ear file in NetBeans ▪ You now have an Ear project containing a War project (just like Eclipse) ▪ Right click on the Project Name and select “build”
  126. Building an Ear file in NetBeans ▪ If you look in the “dist” folder of your project, you will now find an “ear file”
  127. Where you develop – Intellij IDEA ▪ Intellij IDEA ( ▪ Pros – Because of its slant towards Java, code completion and inspections is better and faster than Eclipse – Very fast adding of features and bug fixing – A current web Darling ▪ Cons – The free option is very very limited in comparison to the ultimate version – Not as many plugins as Eclipse and not the default option for such development – Dependent on one company who is not IBM
  128. Building an Ear file in IntelliJ IDEA ▪ We are going to create the same sort of “Ear” project you would get in Eclipse – Just a simple web application, but it gives you the framework to add other modules ▪ Open up IntelliJ IDEA and click “Create New Project”
  129. Building an Ear file in IntelliJ IDEA ▪ Select “Empty Project” and give it a name
  130. Building an Ear file in IntelliJ IDEA ▪ Select your Java version ▪ Select your output directory (this is where your War/Ear file will end up)
  131. Building an Ear file in IntelliJ IDEA ▪ This gives you a blank “Project Structure” ▪ Let’s add a new module by selecting the “+” button and selecting “New Module”
  132. Building an Ear file in IntelliJ IDEA ▪ Select a “Java” module ▪ Give it the name “web” and click next
  133. Building an Ear file in IntelliJ IDEA ▪ Just select “Web application” and “create web.xml”
  134. Building an Ear file in IntelliJ IDEA ▪ You will be taken back to the “Project Structure” screen, which will now have the “web module”, click “add module” again ▪ Select “Java” as on the previous module ▪ This time give it a name of “ear”, then click the “More Settings” at the bottom and deselect “create source root” ▪ Click Next
  135. Building an Ear file in IntelliJ IDEA ▪ Select “Application Server” ▪ If you have not already done so, click new and select “WebSphere Server” ▪ Then define the location of where you have installed your existing WebSphere server
  136. Building an Ear file in IntelliJ IDEA ▪ Next select “JavaEE Application” and just confirm that you have the version of Java you want ▪ Click Finish
  137. Building an Ear file in IntelliJ IDEA ▪ Your now have an application with 2 modules
  138. Building an Ear file in IntelliJ IDEA ▪ But you can see the application descriptor (application.xml) is empty, because the ear file has no modules deployed in it ▪ Let’s fix that
  139. Building an Ear file in IntelliJ IDEA ▪ Got back to you Project Structure via “File” ! “Project Structure”
  140. Building an Ear file in IntelliJ IDEA ▪ There are already two artifacts in the list matching “exploded” (unzipped) versions of the two modules you just created ▪ Select the “ear:ear exploded” artifact and check “Show content of elements”
  141. Building an Ear file in IntelliJ IDEA ▪ Expand the “Available Elements” ! “Artifacts” list ▪ Select “Put into /web.war”
  142. Building an Ear file in IntelliJ IDEA ▪ You will get an error “’Web’ facet (in module ‘web’) isn't registered in ‘application.xml’” ▪ Click the “Fix” button to make this go away, then Click “OK”
  143. Building an Ear file in IntelliJ IDEA ▪ We now have a happier application.xml and an app we can deploy
  144. Building an Ear file in IntelliJ IDEA ▪ To build your application select “Build” ! “Build Artifacts” ▪ When the little popup menu appears, select “ear:ear exploded” ! “Build”
  145. Building an Ear file in IntelliJ IDEA ▪ We now have a deployed application in our project output directory ▪ Oh wait this is still in directories we just want a single “Ear” file
  146. Building an Ear file in IntelliJ IDEA ▪ Go back to the Project Structure, Select the “ear:ear exploded” artifact, and change the dropdown to “JavaEE Application Archive”
  147. Building an Ear file in IntelliJ IDEA ▪ You will see the error about the lack of “META-INF/MANIFEST.MF” ▪ Click “Create Manifest”
  148. Building an Ear file in IntelliJ IDEA ▪ When prompted select the “ear” directory as the location for your “METAINF/MANIFEST.MF” file
  149. Building an Ear file in IntelliJ IDEA ▪ As we are not deploying are modules as Jar files (ours is a War file) we don’t need to fill in the “Main Class” and “Class Path” fields ▪ Also rename name this artifact to something more suitable ▪ Click OK
  150. Building an Ear file in IntelliJ IDEA ▪ Build your Application Again (“Build” ! “Build Artifacts”), using your new Artifact
  151. Building an Ear file in IntelliJ IDEA ▪ Hurrah we now have an “ear” file
  152. Building an Ear file in IntelliJ IDEA ▪ If we rename the ear file to a zip file we can look inside and confirm that the rest of the application is indeed present ☺
  153. Where You Develop - Conclusion ▪ The deck is hugely weighted towards Eclipse for IBM based development due to IBM’s up-todate contributions ▪ The 2 small commercial companies producing WebSphere compatible IDE’s help a great deal in keeping you up-to-date and aware of new features and technologies. ▪ If you are an IBM shop (including Domino): try MyEclipse Blue Edition – – The best mixture of familiarity and cutting edge features at a good price ▪ If you are a startup or a Java shop just starting on IBM WebSphere/Connections: try Intellij IDEA – – At the moment the fastest IDE to write Java apps with an excellent bug fix turn around (and the other Java boys won’t tease you)
  154. Performance Analysis and Troubleshooting 154
  155. Code Optimization ▪ Make your code work first, then worry about speed – You always want working code to fall back on ▪ Is it fast enough? Leave it alone. ▪ An elegant solution that is slightly slower is 
 often better than an ugly solution 
 that is slightly faster ▪ Making code shorter doesn’t make it faster ▪ Keep the code readable and easy to 
 troubleshoot ▪ Don’t assume you know where the bottleneck is “We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil” - Donald Knuth
  156. Static Code Analyzers ▪ FindBugs is a great tool for finding potential problems ▪ Bugs grouped by categories – Scariest – Scary – Troubling ▪ Also subcategories like “Correctness”, “Security”, “Performance”, 
 and “Dodgy Code” ▪ New cloud option for development teams – Rank bugs, assign fixes ▪ ▪
  157. FindBugs
  158. FindBugs
  159. Debugging, Logging, and Unit Testing ▪ Mark and Julian did a 2-hour presentation on debugging, logging, and unit testing at Lotusphere 2012 – Please see the slides at: – ▪ Highlights: – How to add unit testing to Java code in DDE – How to add unit testing to JavaScript code – Debugging Java agents on Notes clients and Domino servers – Debugging Java classes used by XPages – Tips for using Java logging
  160. Common Bottlenecks ▪ Some other guy’s server ▪ Slow database queries ▪ Memory issues – Leaks (less common than you’d think) – Too much cached information • Especially large objects, strings, XML – Strong references ▪ Loading and unloading resources ▪ Non-lazy initialization of objects ▪ Slow or broken network connection
  161. Simulating Poor Network Connections ▪ ▪ ▪ Network Link Conditioner (OSX) – XCode > Open Developer Tool > More Developer Tools
  162. Analyzing Java Memory Usage ▪ Used for: – Tracking down memory leaks – Finding high-memory-use objects (and arrays) – Finding objects that are unexpectedly still in memory ▪ IBM Heap Analyzer – – ▪ YourKit Java profiling app – – ▪ Eclipse Memory Analysis Tool – – –
  163. Generating Heap Dumps with Notes/Domino ▪ Domino XPages – tell http xsp heapdump – XPages Toolbox ( ) ▪ Notes Client (Expeditor) – notesframeworkrcprcplauncher.exe heap -dumps heapdump – writes to by default – You can also do a core (thread) dump with: • notesframeworkrcprcplauncher.exe threads -dumps javacore ▪ Directly from Java –; – writes to when run from an agent
  164. References and Suchnot 164
  165. Resources ▪ Code from this session: – – ▪ Other related presentations we’ve done – – ▪ Links to things we talked about today – On the slides where we talked about the things in question – Please download the slides from the Connect 2014 site – Google is also an excellent resource
  166. Possibly Related Sessions This Week ▪ JMP101: Java for XPages Development • Paul Calhoun, Panagenda; ▪ AD301: What's New on the IBM Social Business Toolkit Version 2.0 • Manish Kataria, IBM; Mark Wallace, IBM ▪ JMP403: Master Class: IBM Connections Troubleshooting • Susan Bulloch, IBM; Greg Presayzen, IBM ▪ BP304: What We Wish We Had Known: Becoming an IBM Connections Administrator • Gabriella Davis, The Turtle Partnership; Paul Mooney, Bluewave Technology ▪ SHOW303: Proper Connections Development for Proper IBM Domino Developers • Mark Myers, London Developer Coop; Matt White, Fynn Consulting Ltd ▪ BP301: An Introduction to Working with the Activity Stream • Mikkel Flindt Heisterberg, OnTime by IntraVision
  167. ▪ Access Connect Online to complete your session surveys using any: – Web or mobile browser – Connect Online kiosk onsite Mark Myers
 London Developer Coop
 Twitter: @stickfight 167 Julian Robichaux
 Twitter: @jrobichaux
  168. Acknowledgements and Disclaimers Availability. References in this presentation to IBM products, programs, or services do not imply that they will be available in all countries in which IBM operates. The workshops, sessions and materials have been prepared by IBM or the session speakers and reflect their own views. They are provided for informational purposes only, and are neither intended to, nor shall have the effect of being, legal or other guidance or advice to any participant. While efforts were made to verify the completeness and accuracy of the information contained in this presentation, it is provided AS-IS without warranty of any kind, express or implied. IBM shall not be responsible for any damages arising out of the use of, or otherwise related to, this presentation or any other materials. Nothing contained in this presentation is intended to, nor shall have the effect of, creating any warranties or representations from IBM or its suppliers or licensors, or altering the terms and conditions of the applicable license agreement governing the use of IBM software. All customer examples described are presented as illustrations of how those customers have used IBM products and the results they may have achieved. Actual environmental costs and performance characteristics may vary by customer. Nothing contained in these materials is intended to, nor shall have the effect of, stating or implying that any activities undertaken by you will result in any specific sales, revenue growth or other results. © Copyright IBM Corporation 2014. All rights reserved. ▪ U.S. Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. ▪ IBM, the IBM logo,, IBM WebSphere, IBM Notes, IBM Connections, Rational, and DB2 are trademarks or registered trademarks of International Business Machines Corporation in the United States, other countries, or both. If these and other IBM trademarked terms are marked on their first occurrence in this information with a trademark symbol (® or ™), these symbols indicate U.S. registered or common law trademarks owned by IBM at the time this information was published. Such trademarks may also be registered or common law trademarks in other countries. A current list of IBM trademarks is available on the Web at “Copyright and trademark information” at ▪ Java and all Java-based trademarks and logos are trademarks or registered trademarks of Oracle and/or its affiliates. ▪ Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both. ▪ Other company, product, or service names may be trademarks or service marks of others. 168