Though there are a few non-Eclipse answers above for this question that does not mention Eclipse, they require path variable changes. An alternative is to use the command line option, java.home, e.g.:
mvn package -Djava.home="C:\Program Files\Java\jdk1.8.0_161\jre"
Notice the \jre at the end - a surprising necessity.