Once upon a time back in the CRM 2011 SDK there was a Java example for connecting directly to CRM Online but nothing for connecting to On Premise IFD organizations. Again this is a port of the C# version that I previously posted to Java. And again I haven't done much Java development so I apologize in advance if the code quality isn't that great. The idea is just to give people needing to connect from a Java application directly to CRM a starting point.
The sample application authenticates to CRM and returns the logged in user's name.
The code to create the SOAP header looks like this: