How do I get the location of the confluence.home directory?

First you need the BootstrapManager (see how to retrieve it) then simply call the following method:

String confluenceHome = bootstrapManager.getConfluenceHome();

The BootstrapManager also has a getConfiguredConfluenceHome method. This method is used during system startup to determine the location of confluence.home from first principles. There is no reason for you to call this method: getConfluenceHome should be sufficient.