SHOW104: 

Practical Java

Mark Myers, London Developer Coop
Julian Robichaux, panagenda

© 2014 IBM Corporation
Who Are These Lovely Speakers?
▪ Mark Myers

– Member of the London Developer Co-op
(londc.com), a group of UK based
devel...
Who Are These Lovely Speakers?
▪ Julian Robichaux

– Developer at panagenda, an Austrian based 

IT management software pr...
Why Are We Here?
▪ To show you practical tips and tricks when dealing with the wider world of Java
▪ To save you from a st...
What Technology Was Used?
▪ Oracle® Java™ and IBM® Java™ (some manner of version 1.6)
▪ IBM (Lotus) Notes® 9.0
▪ IBM WebSp...
Relational Data Access

6
Connection to Relational Databases
▪ When we started writing applications for Connections rather than Domino we went from ...
Connection to Relational Databases – Mapping Databases to
Java
Connection to Relational Databases
▪ To communicate with hibernate we are going to use JPA or Java Persistence API which
g...
JDBC Basics
▪ But why use such an extra Layer, why not just write SQL statements?
▪ Using such a persistence layer gives u...
JDBC Setup – Relational Databases
▪ Relational Database Connections are normally not direct.

JDBC config
on Server

Entit...
Connection to Relational Databases
▪ Connections and WebSphere apps normally do not define their JDBC inside the app, they...
JDBC Setup – Server Side
▪ Your JDBC connections are setup on the WAS server normally by your Admin

This actually provide...
JDBC Setup – Server Side
WebSphere Admin Console

▪ If want to set up a JDBC
connection to a DB2 server on
WebSphere
▪ Fir...
JDBC Setup – Server Side
▪ You will need 2 driver files

– “db2jcc.jar”
– “db2jcc_license_cu.jar”
▪ Are on the server? The...
JDBC Setup – Server Side
Environment Variables

▪ You can Check the location in “Environment” ! “WebSphere Variables”
▪ If...
JDBC Setup – Server Side
New authentication profile

▪ First we want to set up the authentication for the JDBC as if you d...
JDBC Setup – Server Side
New authentication profile

▪ Fill in the User name and Password of the account that has the righ...
JDBC Setup – Server Side
New authentication profile

▪ We now have a new Authentication profile
JDBC Setup – Server Side
New data source

▪ Now Under “Resources” ! JDBC ! “Data Sources” , select a Scope (Normally just ...
JDBC Setup – Server Side
New data source

▪ Enter a human readable “Data Source Name”
▪ And a unique “JNDI Name”. Ensure y...
JDBC Setup – Server Side
New data source

▪ If you have already connected to another data source on this server using the ...
JDBC Setup – Server Side
New data source

▪ We will assume that it is a DB2 database you are connecting to (nearly all Con...
JDBC Setup – Server Side
New data source

▪ As long as the 2 jar driver files we checked before are listed on in the class...
JDBC Setup – Server Side
New data source

▪ Stipulate the name of the database you want to connect to, and its server
▪ Po...
JDBC Setup – Server Side
New data source

▪ Now you will be asked for the security alias you created before
▪ Select them ...
JDBC Setup – Server Side
New data source

▪ Review the summary and if you are happy, click “Next” , then “Save”
JDBC Setup – Server Side
▪ You now have a new JNDI you can use in your code
Now we have a database connection – What Next?
▪ Time to glue our server database connection to code so we can finally do ...
JDBC Setup – Code – Persistence.xml
▪ First up you will want
somewhere for the JNDI you
have just setup to live in your
ap...
JDBC Setup – Code – Persistence.xml
This is the persistence unit name, Remember this

When dealing with WebSphere the tran...
JDBC Setup – Code
▪ Now we have a Persistence
unit (which tells us which
classes we want to glue to the
JDBC setup on WebS...
JDBC Setup – Code

EntityManagerHelper.java

Here is the persistence unit
name from the
persistence.xml
JDBC Setup – Code
▪ We can now create a Data
Access Object file to go with
our actual “Employee” (we will
show you these b...
JDBC Setup – Code

Here we call the
EntityManager from earlier

Table/Class Data Access Object
JDBC Setup – Code
▪ Now lets finally create a
normal java class to use all of
this.
JDBC Setup – Code
Finally use the data in code
Here we are using the
“findbyProfGuid” function
which is a auto generated
f...
JDBC Setup – Code - Demo
Don’t worry this is all done with wizards (in most IDE’s), let us show you

38
JDBC Setup – Code – Demo
A Note About Non-Relational Databases
▪ Before we wrap up relational databases and leave you thinking the world has just g...
A Note About Non-Relational Databases
▪ Domino is classed as a “NoSQL” database, ☺
▪ YOU already have the background and k...
Parsing Connections Feeds
▪ Of course, the Connections API is geared towards using Atom feeds for data access (not
JDBC di...
Connections Feeds – Apache Abdera Example
▪ Quick example using Apache Abdera
▪ Java agent in a Notes database
▪ You will ...
Connections Feeds – Apache Abdera Example
Connections Feeds – Apache Abdera Example
Data Analysis
▪ So you’ve retrieved a bunch of data. Now what?
▪ The most popular data analysis tool still seems to be… sp...
Apache POI Example
Apache POI Example
Data Analysis
▪ What if you have to do the “stuff” for the user?
▪ Need to generate a report?

– Apache POI (just make a f...
Images, PDFs, and Plugins
and Notes and Eclipse too!

50
Lotus Expeditor
▪ The Eclipse-based Notes client is built on top of Lotus Expeditor, which is built on top of
Eclipse
▪ To...
Installing Eclipse
▪ For the Expeditor Toolkit version 6.2.x:

– Download and install Sun Java 1.6 JDK
• http://www.oracle...
Installing the Expeditor Toolkit in Eclipse
▪ Choose the menu option Help > Software Updates…
• There is a slightly differ...
Installing the Expeditor Toolkit in Eclipse
Installing the Expeditor Toolkit in Eclipse
Required

Optional
Creating A Plugin Project
▪ After you install the Toolkit, 

when you create a new 

workspace in Eclipse you will 

see a...
Creating A Plugin Project
▪ From the splash screen, choose the 

menu option File > New > Project
▪ Choose Plug-in Project...
Creating A Plugin Project
▪ Create a project name, then click “Next” to accept the defaults on the next two screens
Creating A Plugin Project
▪ To make this a little easier, choose the 

“Hello World Command” template, which 

is already ...
Creating A Plugin Project
Accessing An Image
▪ This plugin will use the computer’s webcam to capture a picture of the user
▪ We will use the sarxos ...
SIDEBAR: Using a Mac Webcam from VMWare Fusion
▪ Lots of developers use Macs and MacBooks these days

– And VMWare Fusion ...
SIDEBAR: Installing the BootCamp Drivers
▪ The easiest way to install the Bootcamp drivers into VMWare Fusion is to use th...
SIDEBAR: Installing the BootCamp Drivers
SIDEBAR: Installing the BootCamp Drivers
SIDEBAR: Installing the BootCamp Drivers
▪ If you have trouble burning the CD (or need to do it again), the disc image is ...
SIDEBAR: Installing the BootCamp Drivers
▪ Access the CD (or disc image (or files)) from your Windows VM and run setup.exe...
Using the Sarxos Java Webcam Library

adding the files to the project

▪ Download the latest “dist” zip file from https://...
Using the Sarxos Java Webcam Library

setting the build path

▪ Right-click the “lib” folder and 

choose Build Path > Con...
Using the Sarxos Java Webcam Library

adding the files to the binary build

▪ Double-click the plugin.xml entry in the plu...
Using the Sarxos Java Webcam Library

setting the classpath

▪ Go to the “Runtime” tab and add all the webcam jar files to...
Using the Sarxos Java Webcam Library

custom JDialog class

▪ The sarxos webcam library has a custom JPanel that can displ...
Using the Sarxos Java Webcam Library

custom JDialog class (constructor)
Using the Sarxos Java Webcam Library

custom JDialog class (constructor)
Using the Sarxos Java Webcam Library

custom JDialog class (constructor)
Using the Sarxos Java Webcam Library

custom JDialog class (webcam start thread)
Using the Sarxos Java Webcam Library

custom JDialog class (take a snapshot action)
Using the Sarxos Java Webcam Library

custom JDialog class (save snapshot action)
Using the Sarxos Java Webcam Library

calling the dialog from the toolbar action
Using the Sarxos Java Webcam Library

let’s see this baby work
Cropping And Resizing The Image
▪ First you want to get your image as a BufferedImage

– ImageIO.read() for File, InputStr...
Resize Option #1

AffineTransform

▪ AffineTransform is an easy way to resize
▪ Resizing based on a scaling factor, where ...
Resize Option #2

getScaledInstance()

▪ Use BufferedImage.getScaledInstance(width, height, renderingHint)
▪ Rendering hin...
Resize Option #2

getScaledInstance()

Image tempImage = oldBufferedImage.getScaledInstance(width,
height, Image.SCALE_ARE...
Resize Option #3

gradual resize

▪ Draw the image to a java.awt.Graphics2D instance using java.awt.RenderingHints

– Full...
Resize Option #3

gradual resize
do {

!

if (w > targetWidth) {
w = (int)Math.max(w / 2, targetWidth);
h = (int)Math.max(...
Resize Comparison Examples
AffineTransform

getScaledInstance

Gradual resize

90px

45px
Get Some User Information
▪ Next we will get some information about the user to go along with the picture
▪ Since this is ...
Accessing the Notes API From A Plugin
▪ To access IBM Notes from a plugin, use a NotesSessionJob

– You can do almost anyt...
General NotesSessionJob Code Structure
Getting User Information
▪ We can get the user name directly from the Notes session
▪ We will lookup other user informatio...
Getting User Information
Getting User Information
Stick It All in a PDF
▪ Finally, we will put the picture and 

the user info into a PDF for distribution
Java PDF Libraries
▪ Several to choose from:

– Apache FOP
– Apache PDFBox
– PDFJet
– iText
– Many others...
▪ Always chec...
Options for Creating PDFs in iText
▪ Generate the PDF from scratch

– Create a PDF doc in memory
– Add formatting, paragra...
Add the iText JAR to the Eclipse Project
▪ Same process as with the webcam jar files

– Import (or drag) to the “lib” fold...
Simple Wrapper Class for PDF Creation
Simple Wrapper Class for PDF Creation
Simple Wrapper Class for PDF Creation
Simple Wrapper Class for PDF Creation
Putting It All Together
▪ All the heavy-lifting code was put in wrapper classes for ease of use (and reusability)
▪ We cal...
Putting It All Together
Putting It All Together
Tips, Tricks, and Gotchas
▪ Plugins can crash the Notes client

– Be very careful, code defensively
– They can also cause ...
Other IDEs

Checking out the competition

106
Other IDEs We Might Want To Use
▪ As Domino developers you have always developed with Domino Designer given Notes/
Domino ...
Where you develop – Core Eclipse

▪ Eclipse is the default and most common Java IDE, particularly so in the IBM world as i...
Where you develop – Core Eclipse
▪ Pros

– Thousands of plugins
– Widely supported
– Custom Builds.

!

• One of the main ...
Where you develop – Eclipse Custom Builds
▪ Some of the popular ones are

– Domino Designer (we think you know this one)
–...
Where you develop – IBM Rational Application Studio Eclipse
Build
▪ IBM Rational Application Developer for WebSphere Softw...
Where you develop – Genuitec MyEclipse Blue Eclipse build
▪ MyEclipse Blue Edition is a direct competitor to IBM’s Rationa...
Bit of background - What are WAR and EAR files
▪ A .War file (Web application ARchive) is a file used to distribute a coll...
Setting up Eclipse for WebSphere
▪ If you are not using an Eclipse instance built for
WebSphere development you will need ...
Setting up Eclipse for WebSphere

▪ Once the plugin is installed you can go to the Servers Tab (nearly always at the botto...
Setting up Eclipse for WebSphere

▪ You can now select the WebSphere
server v8.0 option.
▪ Click Next
Setting up Eclipse for WebSphere

▪ Select the Server location and which
Profile you want to use
▪ Click Finish

Tip: try ...
Setting up Eclipse for WebSphere - Gotcha 1

▪ WebSphere is NOT under
“Download additional server
adaptors” on the server ...
Setting up Eclipse for WebSphere - Gotcha 2

▪ If you are Installing IBM Rational
application developer you have to
select...
Eclipse Showroom Demo
Where you develop – NetBeans
▪ The Longtime Alternative to Eclipse, developed independently and now owned by Oracle
▪ Pros...
Building an Ear file in NetBeans
▪ Click “File” ! “New Project”
▪ Select “Java EE” ! “Enterprise
Application”
▪ Click Next
Building an Ear file in NetBeans
▪ Give your Application a Name
and a Location
▪ Click Next
Building an Ear file in NetBeans
▪ As there is no WebSphere
integration select “Glassfish Server”
▪ Ensure you Select “Cre...
Building an Ear file in NetBeans
▪ You now have an Ear project containing a War
project (just like Eclipse)
▪ Right click ...
Building an Ear file in NetBeans
▪ If you look in the “dist” folder
of your project, you will now
find an “ear file”
Where you develop – Intellij IDEA
▪ Intellij IDEA (http://www.jetbrains.com/idea/)
▪ Pros

– Because of its slant towards ...
Building an Ear file in IntelliJ IDEA
▪ We are going to create the same sort of
“Ear” project you would get in Eclipse

– ...
Building an Ear file in IntelliJ IDEA
▪ Select “Empty Project” and give it a name
Building an Ear file in IntelliJ IDEA
▪ Select your Java version
▪ Select your output directory
(this is where your War/Ea...
Building an Ear file in IntelliJ IDEA
▪ This gives you a blank “Project Structure”
▪ Let’s add a new module by selecting t...
Building an Ear file in IntelliJ IDEA
▪ Select a “Java” module
▪ Give it the name “web” and click next
Building an Ear file in IntelliJ IDEA
▪ Just select “Web application” and “create
web.xml”
Building an Ear file in IntelliJ IDEA
▪ You will be taken back to the “Project
Structure” screen, which will now have the
...
Building an Ear file in IntelliJ IDEA
▪ Select “Application Server”
▪ If you have not already done so,
click new and selec...
Building an Ear file in IntelliJ IDEA
▪ Next select “JavaEE Application” and just confirm
that you have the version of Jav...
Building an Ear file in IntelliJ IDEA
▪ Your now have an application with
2 modules
Building an Ear file in IntelliJ IDEA
▪ But you can see the application descriptor (application.xml) is empty, because the...
Building an Ear file in IntelliJ IDEA
▪ Got back to you Project Structure via “File” ! “Project Structure”
Building an Ear file in IntelliJ IDEA
▪ There are already two artifacts in the list matching “exploded” (unzipped) version...
Building an Ear file in IntelliJ IDEA
▪ Expand the “Available Elements” ! “Artifacts” list
▪ Select “Put into /web.war”
Building an Ear file in IntelliJ IDEA
▪ You will get an error “’Web’ facet (in module ‘web’) isn't registered in ‘applicat...
Building an Ear file in IntelliJ IDEA
▪ We now have a happier application.xml and an app we can deploy
Building an Ear file in IntelliJ IDEA
▪ To build your application select “Build” ! “Build Artifacts”
▪ When the little pop...
Building an Ear file in IntelliJ IDEA
▪ We now have a deployed application in our project output directory
▪ Oh wait this ...
Building an Ear file in IntelliJ IDEA
▪ Go back to the Project Structure, Select the “ear:ear exploded” artifact, and chan...
Building an Ear file in IntelliJ IDEA
▪ You will see the error about the lack of “META-INF/MANIFEST.MF”
▪ Click “Create Ma...
Building an Ear file in IntelliJ IDEA
▪ When prompted select the “ear”
directory as the location for your “METAINF/MANIFES...
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 nee...
Building an Ear file in IntelliJ IDEA

▪ Build your Application Again (“Build” ! “Build
Artifacts”), using your new Artifa...
Building an Ear file in IntelliJ IDEA
▪ Hurrah we now have an “ear” file
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 re...
Where You Develop - Conclusion
▪ The deck is hugely weighted towards Eclipse for IBM based development due to IBM’s up-tod...
Performance Analysis
and Troubleshooting

154
Code Optimization
▪ Make your code work first, then worry about speed

– You always want working code to fall back on
▪ Is...
Static Code Analyzers
▪ FindBugs is a great tool for finding potential problems
▪ Bugs grouped by categories

– Scariest
–...
FindBugs
FindBugs
Debugging, Logging, and Unit Testing
▪ Mark and Julian did a 2-hour presentation on debugging, logging, and unit testing a...
Common Bottlenecks
▪ Some other guy’s server
▪ Slow database queries
▪ Memory issues

– Leaks (less common than you’d thin...
Simulating Poor Network Connections
▪ http://www.charlesproxy.com
▪ http://jagt.github.io/clumsy
▪ Network Link Conditione...
Analyzing Java Memory Usage
▪ Used for:

– Tracking down memory leaks
– Finding high-memory-use objects (and arrays)
– Fin...
Generating Heap Dumps with Notes/Domino
▪ Domino XPages
– tell http xsp heapdump

– XPages Toolbox ( http://www.openntf.or...
References and Suchnot

164
Resources
▪ Code from this session:

– http://londondevelopercoop.com/ldc.nsf/pages/goodies
– http://nsftools.com/presenta...
Possibly Related Sessions This Week
▪ JMP101: Java for XPages Development
• Paul Calhoun, Panagenda;

▪ AD301: What's New ...
▪ Access Connect Online to complete your session surveys using any:
– Web or mobile browser
– Connect Online kiosk onsite
...
Acknowledgements and Disclaimers
Availability. References in this presentation to IBM products, programs, or services do n...
Upcoming SlideShare
Loading in...5
×

Connect2014 Show104: Practical Java

1,679

Published on

Julian Robichaux, panagenda
Mark Myers, London Developer Group

IBM Connect 2014, Orlando

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,679
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
67
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Connect2014 Show104: Practical Java"

  1. 1. SHOW104: 
 Practical Java Mark Myers, London Developer Coop Julian Robichaux, panagenda © 2014 IBM Corporation
  2. 2. Who Are These Lovely Speakers? ▪ Mark Myers – Member of the London Developer Co-op (londc.com), 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. 3. Who Are These Lovely Speakers? ▪ Julian Robichaux – Developer at panagenda, an Austrian based 
 IT management software provider – Purveyor of nsftools.com – 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. 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. 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. 6. Relational Data Access 6
  7. 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.org/ ▪ 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. 8. Connection to Relational Databases – Mapping Databases to Java
  9. 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. 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 (http://sourceforge.net/projects/c3p0/) 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. 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. 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. 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. 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. 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. 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. 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. 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. 19. JDBC Setup – Server Side New authentication profile ▪ We now have a new Authentication profile
  20. 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. 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. 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. 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. 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. 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. 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. 27. JDBC Setup – Server Side New data source ▪ Review the summary and if you are happy, click “Next” , then “Save”
  28. 28. JDBC Setup – Server Side ▪ You now have a new JNDI you can use in your code
  29. 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. 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. 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. 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. 33. JDBC Setup – Code EntityManagerHelper.java Here is the persistence unit name from the persistence.xml
  34. 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. 35. JDBC Setup – Code Here we call the EntityManager from earlier Table/Class Data Access Object
  36. 36. JDBC Setup – Code ▪ Now lets finally create a normal java class to use all of this.
  37. 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. 38. JDBC Setup – Code - Demo Don’t worry this is all done with wizards (in most IDE’s), let us show you 38
  39. 39. JDBC Setup – Code – Demo
  40. 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. 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 ( http://couchdb.apache.org ) – SimpleDB ( http://aws.amazon.com/simpledb ) – MongoDB ( http://www.mongodb.org )
  42. 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 – http://abdera.apache.org – Handles HTTP connections and authentication as well as parsing ▪ There are also some nice wrappers around the API/feeds in the Social Business Toolkit – http://ibmsbt.openntf.org – See AD301: What's New on the IBM Social Business Toolkit later this week
  43. 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. 44. Connections Feeds – Apache Abdera Example
  45. 45. Connections Feeds – Apache Abdera Example
  46. 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 – http://poi.apache.org ▪ 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. 47. Apache POI Example
  48. 48. Apache POI Example
  49. 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 – http://www.eclipse.org/birt ▪ Need to make some graphs and charts? – BiRT might have what you need – jFreeChart – http://www.jfree.org/jfreechart ▪ Need to do some heavy number crunching? – FreeHEP (HEP = High Energy Physics) – http://java.freehep.org – SCaVis (formerly jHepWork) – http://jwork.org/scavis from http://java.freehep.org/freehep-legoplot
  50. 50. Images, PDFs, and Plugins and Notes and Eclipse too! 50
  51. 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 – http://www.ibm.com/developerworks/lotus/downloads/toolkits.html – http://wiki.eclipse.org/Older_Versions_Of_Eclipse ▪ Good list of steps and other information in this wiki article: – http://www-10.lotus.com/ldd/lewiki.nsf/dx/ Getting_started_with_the_Lotus_Expeditor_Toolkit_6.2.1 – (or just look at the next few slides)
  52. 52. Installing Eclipse ▪ For the Expeditor Toolkit version 6.2.x: – Download and install Sun Java 1.6 JDK • http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloadsjavase6-419409.html – Download Eclipse for RCP Plugin Developers, version 3.4 (Ganymede) • http://www.eclipse.org/downloads/packages/release/ganymede/sr2 – Unzip the Eclipse ZIP file using 7-Zip or a similar tool ( http://www.7-zip.org ) • 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 • http://www.ibm.com/developerworks/lotus/downloads/toolkits.html • 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. 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. 54. Installing the Expeditor Toolkit in Eclipse
  55. 55. Installing the Expeditor Toolkit in Eclipse Required Optional
  56. 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. 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 
 version)
  58. 58. Creating A Plugin Project ▪ Create a project name, then click “Next” to accept the defaults on the next two screens
  59. 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. 60. Creating A Plugin Project
  61. 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 – http://webcam-capture.sarxos.pl – 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: https://code.google.com/p/bridj/downloads/list ) – 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. 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. 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. 64. SIDEBAR: Installing the BootCamp Drivers
  65. 65. SIDEBAR: Installing the BootCamp Drivers
  66. 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. 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: – http://www.apple.com/support/bootcamp/downloads
  68. 68. Using the Sarxos Java Webcam Library
 adding the files to the project ▪ Download the latest “dist” zip file from https://github.com/sarxos/webcam-capture – I started with http://www.sarxos.pl/repo/maven2/com/github/sarxos/webcamcapture/0.3.10-RC6/webcam-capture-0.3.10-RC6-dist.zip • 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. 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. 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. 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. 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. 73. Using the Sarxos Java Webcam Library
 custom JDialog class (constructor)
  74. 74. Using the Sarxos Java Webcam Library
 custom JDialog class (constructor)
  75. 75. Using the Sarxos Java Webcam Library
 custom JDialog class (constructor)
  76. 76. Using the Sarxos Java Webcam Library
 custom JDialog class (webcam start thread)
  77. 77. Using the Sarxos Java Webcam Library
 custom JDialog class (take a snapshot action)
  78. 78. Using the Sarxos Java Webcam Library
 custom JDialog class (save snapshot action)
  79. 79. Using the Sarxos Java Webcam Library
 calling the dialog from the toolbar action
  80. 80. Using the Sarxos Java Webcam Library
 let’s see this baby work
  81. 81. Cropping And Resizing The Image ▪ First you want to get your image as a BufferedImage – ImageIO.read() 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. 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 http://en.wikipedia.org/wiki/Image_scaling AffineTransformOp op = new AffineTransformOp (AffineTransform.getScaleInstance(scale, scale), AffineTransformOp.TYPE_BICUBIC); bi = op.filter(bi, null);
  83. 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. 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. 85. Resize Option #3
 gradual resize ▪ Draw the image to a java.awt.Graphics2D instance using java.awt.RenderingHints – Full list of hints at http://docs.oracle.com/javase/7/docs/api/java/awt/ 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:// today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html ▪ Generally much better image quality than getScaledInstance
  86. 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. 87. Resize Comparison Examples AffineTransform getScaledInstance Gradual resize 90px 45px
  88. 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. 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. 90. General NotesSessionJob Code Structure
  91. 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. 92. Getting User Information
  93. 93. Getting User Information
  94. 94. Stick It All in a PDF ▪ Finally, we will put the picture and 
 the user info into a PDF for distribution
  95. 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 – http://itextpdf.com
  96. 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 http://stderr.org/doc/libitext-java-doc/www/tutorial/index.html ▪ Use an existing PDF as a template – Interesting technique described by Jake Howlett (codestore.net) – 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 http://www.manning.com/lowagie2/ samplechapter6.pdf
  97. 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. 98. Simple Wrapper Class for PDF Creation
  99. 99. Simple Wrapper Class for PDF Creation
  100. 100. Simple Wrapper Class for PDF Creation
  101. 101. Simple Wrapper Class for PDF Creation
  102. 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. 103. Putting It All Together
  104. 104. Putting It All Together
  105. 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 – http://www.eclipse.org/articles/article.php?file=Article-Swing-SWT-Integration/ index.html ▪ Examples and info on extending the Notes menus and toolbar – http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Developing_Menus_and_Actions ▪ Example of adding a PDF directly to a Notes document without writing to the file system: – http://londondevelopercoop.com/ldc.nsf/pages/goodies (our Lotusphere 2012 session)
  106. 106. Other IDEs Checking out the competition 106
  107. 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 (http://www.eclipse.org/) – NetBeans (https://netbeans.org/) – Intellij IDEA (http://www.jetbrains.com/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. 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. 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. 110. Where you develop – Eclipse Custom Builds ▪ Some of the popular ones are – Domino Designer (we think you know this one) – Scala (http://scala-ide.org/) – Adobe Flash Builder (http://www.adobe.com/uk/products/flash-builder.html) – Spring Tool Suite (http://spring.io/tools/sts) ! ▪ 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. 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 (http://www.ibm.com/developerworks/downloads/r/rad/) ▪ 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. 112. Where you develop – Genuitec MyEclipse Blue Eclipse build ▪ MyEclipse Blue Edition is a direct competitor to IBM’s Rational Application Developer (http://www.myeclipseide.com/blue/) ▪ 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. 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. 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. 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. 116. Setting up Eclipse for WebSphere ▪ You can now select the WebSphere server v8.0 option. ▪ Click Next
  117. 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. 118. Setting up Eclipse for WebSphere - Gotcha 1 ▪ WebSphere is NOT under “Download additional server adaptors” on the server Definition wizard
  119. 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. 120. Eclipse Showroom Demo
  121. 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 (http://plugins.netbeans.org/ plugin/40546/wasce-plugin) • And an Ant script work around (http://nicetolearn.blogspot.gr/2013/07/using-netbeans-withwebsphere.html) – Less 3rd party support than competitors
  122. 122. Building an Ear file in NetBeans ▪ Click “File” ! “New Project” ▪ Select “Java EE” ! “Enterprise Application” ▪ Click Next
  123. 123. Building an Ear file in NetBeans ▪ Give your Application a Name and a Location ▪ Click Next
  124. 124. Building an Ear file in NetBeans ▪ As there is no WebSphere integration select “Glassfish Server” ▪ Ensure you Select “Create Web Application Module”
  125. 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. 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. 127. Where you develop – Intellij IDEA ▪ Intellij IDEA (http://www.jetbrains.com/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. 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. 129. Building an Ear file in IntelliJ IDEA ▪ Select “Empty Project” and give it a name
  130. 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. 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. 132. Building an Ear file in IntelliJ IDEA ▪ Select a “Java” module ▪ Give it the name “web” and click next
  133. 133. Building an Ear file in IntelliJ IDEA ▪ Just select “Web application” and “create web.xml”
  134. 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. 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. 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. 137. Building an Ear file in IntelliJ IDEA ▪ Your now have an application with 2 modules
  138. 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. 139. Building an Ear file in IntelliJ IDEA ▪ Got back to you Project Structure via “File” ! “Project Structure”
  140. 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. 141. Building an Ear file in IntelliJ IDEA ▪ Expand the “Available Elements” ! “Artifacts” list ▪ Select “Put into /web.war”
  142. 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. 143. Building an Ear file in IntelliJ IDEA ▪ We now have a happier application.xml and an app we can deploy
  144. 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. 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. 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. 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. 148. Building an Ear file in IntelliJ IDEA ▪ When prompted select the “ear” directory as the location for your “METAINF/MANIFEST.MF” file
  149. 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. 150. Building an Ear file in IntelliJ IDEA ▪ Build your Application Again (“Build” ! “Build Artifacts”), using your new Artifact
  151. 151. Building an Ear file in IntelliJ IDEA ▪ Hurrah we now have an “ear” file
  152. 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. 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 – http://www.myeclipseide.com/blue – 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 – http://www.jetbrains.com/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. 154. Performance Analysis and Troubleshooting 154
  155. 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. 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 ▪ http://findbugs.sourceforge.net ▪ http://www.cs.umd.edu/~pugh/MistakesThatMatter.pdf
  157. 157. FindBugs
  158. 158. FindBugs
  159. 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: – http://londondevelopercoop.com/ldc.nsf/pages/goodies ▪ 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. 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. 161. Simulating Poor Network Connections ▪ http://www.charlesproxy.com ▪ http://jagt.github.io/clumsy ▪ Network Link Conditioner (OSX) – XCode > Open Developer Tool > More Developer Tools
  162. 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 – https://www.ibm.com/developerworks/community/alphaworks/tech/heapanalyzer – http://www-01.ibm.com/support/docview.wss?uid=swg27006624&aid=1 ▪ YourKit Java profiling app – http://yourkit.com – http://notesin9.com/index.php/2012/11/29/notesin9-091-xpages-memory-profilingpart-1 ▪ Eclipse Memory Analysis Tool – http://www.eclipse.org/mat/downloads.php – http://lazynotesguy.net/blog/2013/08/30/wheres-my-memory-gone-peeking-insidejvms-heap-part-1-installation – http://lazynotesguy.net/blog/2013/10/04/peeking-inside-jvms-heap-part-2-usage
  163. 163. Generating Heap Dumps with Notes/Domino ▪ Domino XPages – tell http xsp heapdump – XPages Toolbox ( http://www.openntf.org/p/XPages%20Toolbox ) ▪ Notes Client (Expeditor) – notesframeworkrcprcplauncher.exe -com.ibm.rcp.core.logger#dump heap -dumps heapdump – writes to notesdataworkspacelogsheapdump.###.phd by default – You can also do a core (thread) dump with: • notesframeworkrcprcplauncher.exe -com.ibm.rcp.core.logger#dump threads -dumps javacore ▪ Directly from Java – com.ibm.jvm.Dump.HeapDump(); – writes to notesframeworkheapdump.###.phd when run from an agent
  164. 164. References and Suchnot 164
  165. 165. Resources ▪ Code from this session: – http://londondevelopercoop.com/ldc.nsf/pages/goodies – http://nsftools.com/presentations ▪ Other related presentations we’ve done – http://londondevelopercoop.com/ldc.nsf/pages/goodies – http://nsftools.com/presentations ▪ 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. 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. 167. ▪ Access Connect Online to complete your session surveys using any: – Web or mobile browser – Connect Online kiosk onsite Mark Myers
 London Developer Coop
 mark@energywins.co.uk
 Twitter: @stickfight 167 Julian Robichaux
 panagenda
 jrobichaux@panagenda.com
 Twitter: @jrobichaux
  168. 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.com, 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 www.ibm.com/legal/copytrade.shtml ▪ 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×