How to solve error "Could not find tools.jar" when a module is deployed

When you follow Liferay tutorials, especially when creating a portlet, this error usually appears. 

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':modules:hello:compileJava'.
> Could not find tools.jar. Please check that /usr/lib/jvm/java-1.8.0-openjdk- contains a valid JDK installation.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

This just means that the tools.jar is not found under the directory configured as Java home.

This is solved right clicking the Gradle Task "deploy", and selecting "Open Gradle Run Configuration...".

Go to the Java Home Tab, and set the correct directory to the JDK directory

Click Apply. Try to run again the "deploy" task. It should run fine now.