The "trusty" maven package pulls in openjdk-7-jre-headless. Install it using:

sudo apt-get install maven

Add the Java 7 JDK:

sudo apt-get install openjdk-7-jdk

Java 8 is newer than "trusty", so it needs to be taken from a backport:

sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install -y openjdk-8-jdk

Switch between Java 7 and Java 8:

update-alternatives --list javac



Switch to Java 7:

sudo update-alternatives --set javac $(update-alternatives --list javac | grep java-7)