title: exec-maven-plugin: Can I run exec:exec goal without first running the toolchains:toolchain goal?
body: <p>I've inherited an application that only compiles and runs in Java 1.8. Because I don't want to make Java 1.8 the primary jvm on my machine, I felt that the best way to manage this was through Maven toolchains. Configuring the maven-compiler-plugin was pretty straight forward, but I also want to add the ability to execute the service via Maven in order to take advantage of the toolchain I have configured for 1.8.</p>
  <p>The challenge is that I don't seem to be able to get the exec-maven-plugin to use the toolchain as documented. According to the documentation, I would think that the exec-maven-plugin would utilize the maven-toolchains-plugin as needed. However, in order to get <code>exec:exec</code> to use the right toolchain, I have to use:</p>
  <p><code>mvn toolchains:toolchain exec:exec</code></p>
  <p>This works, but the <a href="https://www.mojohaus.org/exec-maven-plugin/examples/example-exec-using-toolchains.html#The_.22jdk.22_Toolchain" rel="nofollow noreferrer">documentation</a> leads me to think that the toolchain would be configured automatically without me needing to execute the <code>toolchains:toolchain</code> goal.</p>
  <p>pom.xml</p>
  <pre><code>&lt;build&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-toolchains-plugin&lt;/artifactId&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;goals&gt;
              &lt;goal&gt;toolchain&lt;/goal&gt;
            &lt;/goals&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
        &lt;configuration&gt;
          &lt;toolchains&gt;
            &lt;jdk&gt;
              &lt;version&gt;1.8&lt;/version&gt;
            &lt;/jdk&gt;
          &lt;/toolchains&gt;
        &lt;/configuration&gt;
      &lt;/plugin&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;arguments&gt;
            &lt;argument&gt;-classpath&lt;/argument&gt;
            &lt;classpath&gt;&lt;/classpath&gt;
            &lt;argument&gt;com.my.Main&lt;/argument&gt;
          &lt;/arguments&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  <p>toolchains.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF8&quot;?&gt;
  &lt;toolchains&gt;
    &lt;toolchain&gt;
      &lt;type&gt;jdk&lt;/type&gt;
      &lt;provides&gt;
        &lt;id&gt;1.8&lt;/id&gt;
        &lt;version&gt;1.8&lt;/version&gt;
      &lt;/provides&gt;
      &lt;configuration&gt;
        &lt;jdkHome&gt;/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home&lt;/jdkHome&gt;
      &lt;/configuration&gt;
    &lt;/toolchain&gt;
  &lt;/toolchains&gt;
  </code></pre>
  <p>Additional Note: I also tried configuring the exec-maven-plugin to run on <code>exec:java</code> with the following configuration:</p>
  <pre><code>&lt;configuration&gt;
    &lt;mainClass&gt;com.my.Main&lt;/mainClass&gt;
  &lt;/configuration&gt;
  </code></pre>
  <p>However this does not work, not even with <code>mvn toolchains:toolchain exec:java</code>.</p>
  <p>Is there a way to configure this so that I only have to run <code>mvn exec:exec</code>, or <code>mvn exec:java</code>?</p>