This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I'm not aware of any bullet proof strategy for such a thing. If the J2EE_HOME environment variable is set, then on Windows machines, java -DJ2EE_HOME=%J2EE_HOME% Foo should work, and on Linux or Mac machines java -DJ2EE_HOME=$J2EE_HOME Foo should work to then be able to use System.getProperty("J2EE_HOME") in your Foo application. So, knowing what I know how to do and faced with your problem, I'd probably make scripts (batch for windows, and a shell script for Linux/Mac) that ran the appropriate command from above, have the client execute the correct script for their OS, and then if the J2EE_HOME environment variable were not set, either prompt for the location of the J2EE installation and let the user select that it was not installed, or just assume that it was not properly installed.