title: Bad version of java when running maven exec plugin
body: <p>My current version of java is 7:</p>
  
  <pre><code>java -version
  java version "1.7.0_80"
  Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
  Java HotSpot(TM) Server VM (build 24.80-b11, mixed mode)
  </code></pre>
  
  <p>and I have command <code>mvn8</code> where is set <code>java_home</code> to 8:</p>
  
  <pre><code>mvn8 -version
  Java HotSpot(TM) Server VM warning: ignoring option MaxPermSize=512m; support was removed in 8.0
  Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
  Maven home: /home/.../apache-maven-3.0.3
  Java version: 1.8.0_66, vendor: Oracle Corporation
  Java home: /home/.../jdk1.8.0_66/jre
  Default locale: en_US, platform encoding: UTF-8
  OS name: "linux", version: "3.13.0-45-generic", arch: "i386", family: "unix"
  </code></pre>
  
  <p>And now the problem. When I run one of my profile(there is maven exec plugin which generated files) in project:</p>
  
  <pre><code>mvn8 exec:exec -P mo2ja -o
  </code></pre>
  
  <p>I got the exception:</p>
  
  <pre><code>Java HotSpot(TM) Server VM warning: ignoring option MaxPermSize=512m; support was removed in 8.0
  [INFO] Scanning for projects...
  ...
   ERROR:java.time.LocalDateTime cannot be resolved to a type. 
  ERROR:java.time.LocalDate cannot be resolved to a type. 
  [ERROR] Command execution failed.
  org.apache.commons.exec.ExecuteException: Process exited with an error: 2 (Exit value: 2)
      at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:404)
      at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
      at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:764)
      at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:711)
      at org.codehaus.mojo.exec.ExecMojo.execute(ExecMojo.java:289)
      at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
      at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
      at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
      at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
      at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
      at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
      at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
      at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
      at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
      at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
  </code></pre>
  
  <p>So it seems it still takes my system java. Why when mvn version print java8 ? When I change my system java then it work OK. This is some feature of maven or it can be plugin problem which I use ?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>when I debug maven exec plugin I see this line:</p>
  
  <pre><code>[DEBUG] Executing command line: java -classpath ... org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader -control definitions.model -models entity.model,dao.model -source src/main/resources -target src-gen
  </code></pre>
  
  <p>so question is how to use same java version as I am executing mvn</p>
  
  <p>here is my profile:</p>
  
  <pre><code>    &lt;profile&gt;
          &lt;id&gt;mo2ja&lt;/id&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.sqlproc.model&lt;/groupId&gt;
                  &lt;artifactId&gt;sqlmodel&lt;/artifactId&gt;
                  &lt;scope&gt;runtime&lt;/scope&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
          &lt;build&gt;
              &lt;plugins&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                      &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
                      &lt;configuration&gt;
                          &lt;executable&gt;java&lt;/executable&gt;
                          &lt;classpathScope&gt;runtime&lt;/classpathScope&gt;
                          &lt;arguments&gt;
                              &lt;argument&gt;-classpath&lt;/argument&gt;
                              &lt;classpath&gt;
                                  &lt;dependency&gt;org.sqlproc.model:sqlmodel&lt;/dependency&gt;
                                  &lt;dependency&gt;mysql:mysql-connector-java&lt;/dependency&gt;
                                  &lt;dependency&gt;org.sqlproc:sql-processor&lt;/dependency&gt;
                                  &lt;dependency&gt;org.slf4j:slf4j-api&lt;/dependency&gt;
                              &lt;/classpath&gt;
                              &lt;argument&gt;org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader&lt;/argument&gt;
                              &lt;argument&gt;-control&lt;/argument&gt;
                              &lt;argument&gt;definitions.model&lt;/argument&gt;
                              &lt;argument&gt;-models&lt;/argument&gt;
                              &lt;argument&gt;entity.model,dao.model&lt;/argument&gt;
                              &lt;argument&gt;-source&lt;/argument&gt;
                              &lt;argument&gt;src/main/resources&lt;/argument&gt;
                              &lt;argument&gt;-target&lt;/argument&gt;
                              &lt;argument&gt;src-gen&lt;/argument&gt;
                          &lt;/arguments&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
              &lt;/plugins&gt;
          &lt;/build&gt;
      &lt;/profile&gt;
  </code></pre>