I installed 2 versions of java on my machine, 1.7 and 1.8. to create my java projects i use maven 3.5.0.
There are some cases when I need to build a java project using java 1.7, so I change my environment variable %JAVA_HOME%to "C:\Program Files\Java\jdk1.7.0_80"from "C:\Program Files\Java\jdk1.8.0_131".
Then I thought that if I can do this, then pom.xml will determine the java version by which the project should be created.
At first, my pom.xml looked like this:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
...
</plugins>
as you can see, there are tags <source>and <target>, but these tags do not work for java 1.7.1.8, maybe they worked for earlier versions.
So I had to make some changes to Mavens "settings.xml" and to the "pom.xml" files:
settings.xml
<profiles>
<profile>
<id>compiler</id>
<properties>
<JAVA_1_7_HOME>C:\Program Files\Java\jdk1.7.0_80\bin\javac</JAVA_1_7_HOME>
<JAVA_1_8_HOME>C:\Program Files\Java\jdk1.8.0_131\bin\javac</JAVA_1_8_HOME>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>compiler</activeProfile>
</activeProfiles>
pom.xml
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<executable>${JAVA_1_7_HOME}</executable>
<verbose>true</verbose>
<fork>true</fork>
</configuration>
</plugin>
...
</plugins>
mvn install, !!! ${JAVA_1_8_HOME}, jar .
MANIFEST.MF . JDK - 1.8.0_161, MANIFEST.MF -, jdk .
, Maven ( mvn.cmd) % JAVA_HOME% java. % JAVA_HOME%, java -version, 1.8.0_161 ( JRE).
mvn.cmd
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%"=="" goto OkJHome
for %%i in (java.exe) do set "JAVACMD=%%~$PATH:i"
goto checkJCmd
mvn.cmd, java 7, pom.xml?
mvn.cmd jdk MANIFEST.MF?