exec-maven-plugin icon indicating copy to clipboard operation
exec-maven-plugin copied to clipboard

Plugin does not use jdk from toolchains plugin

Open janweinschenker opened this issue 8 years ago • 12 comments

I'm trying execute JDK9 java code using the exec:exec goal. The executabe is the java executable from the JDK9 with Jigsaw. Maven itself runs with a JDK8 JVM.

Although I configured the JDK9 via jdk toolchain, exec-maven-plugin keeps using the jdk8-java-executable.

Within the very same pom.xml I am using the maven-compiler-plugin, which recognizes the toolchain and correctly uses the version 9 javacexecutable.

What am I doing wrong?

janweinschenker avatar Jul 05 '16 07:07 janweinschenker

Can you show your pom configuration as well as your toolchains.xml file...?

khmarbaise avatar Jul 07 '16 13:07 khmarbaise

Hi, I have the same problem with JDK 8 as the toolchain (and JDK7 as the maven executable).

The toolchain is used for compilation but that's all.

Here is my maven config:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-toolchains-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>toolchain</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <toolchains>
                        <jdk>
                            <version>1.8</version>
                        </jdk>
                    </toolchains>
                </configuration>
            </plugin>
<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <!-- Run with "mvn compile maven-dependency-plugin:properties exec:exec" -->
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.5.0</version>
                <extensions>true</extensions>
                <configuration>
                    <mainClass>org.ow2.petals.cockpit.server.CockpitApplication</mainClass>
                    <workingDirectory>target/classes</workingDirectory>
                    <toolchain>jdk</toolchain>  
                    <executable>java</executable>
                    <arguments>
                        <!-- Debug -->
                        <!-- argument>-Xdebug<argument -->
                        <!-- argument>-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005<argument -->

                        <!-- Configure memory settings as needed -->
                        <!-- argument>-Xmx1000m</argument -->

                        <!-- Turn off before production -->
                        <argument>-Dco.paralleluniverse.fibers.verifyInstrumentation=true</argument>

                        <!-- Quasar Agent for JDK 8 -->
                        <argument>-javaagent:${co.paralleluniverse:quasar-core:jar:jdk8}</argument> <!-- Add "=b" to force instrumenting blocking calls like Thread.sleep() -->

                        <!-- Classpath -->
                        <argument>-classpath</argument>
                        <classpath />

                        <!-- Main class -->
                        <argument>org.ow2.petals.cockpit.server.CockpitApplication</argument>
                    </arguments>
                </configuration>
            </plugin>
<?xml version="1.0" encoding="UTF8"?>
<toolchains>
  <!-- JDK toolchains -->
  <toolchain>
    <type>jdk</type>
    <provides>
      <version>1.6</version>
      <vendor>oracle</vendor>
    </provides>
    <configuration>
      <jdkHome>/usr/lib/jvm/java-6-jdk/</jdkHome>
    </configuration>
  </toolchain>
  <toolchain>
    <type>jdk</type>
    <provides>
      <version>1.7</version>
      <vendor>oracle</vendor>
    </provides>
    <configuration>
      <jdkHome>/usr/lib/jvm/java-7-jdk/</jdkHome>
    </configuration>
  </toolchain>
  <toolchain>
    <type>jdk</type>
    <provides>
      <version>1.8</version>
      <vendor>openjdk</vendor>
    </provides>
    <configuration>
      <jdkHome>/usr/lib/jvm/java-8-openjdk/</jdkHome>
    </configuration>
  </toolchain>
</toolchains>

victornoel avatar Jul 11 '16 09:07 victornoel

Please check here: http://www.mojohaus.org/exec-maven-plugin/examples/example-exec-using-toolchains.html I think you mistaken JDK with execution of tools...

khmarbaise avatar Jul 13 '16 18:07 khmarbaise

Sorry, I can't see where my example differs from the documentation.

Isn't the support of toolchains in the exec plugin supposed to setup a path where to search for the tool? The page says about the jdk toolchain

It searches the bin folder of the specified JDK for the requested tool

I was thus expecting for <executable>java</executable> to be searched in the path of the jdk toolchain. Do you say it is not the case?

Thank you

victornoel avatar Jul 14 '16 12:07 victornoel

Hi all,

you can find my pom.xml and the toolchains.xml here: https://github.com/janweinschenker/jdk9-jigsaw-http2

best regards Jan

janweinschenker avatar Jul 25 '16 09:07 janweinschenker

This issue is already two years old. I now stumbled over the same problem when trying to run a program with JDK11 from Maven running with JDK10. I also don't see what is wrong with the setup and expectation described here.

In addition I tried to achieve the same goal using the paths toolchain and this also does not work. If I explicitly set the executable to the full path of the java program everything works as expected but any attempt to use any toolchain instead fails.

mipastgt avatar Jul 06 '18 14:07 mipastgt

Hi, I had the same issue when I tried to use toolchains with maven-exec-plugin and this is what i've found. When we run mvn exec:exec goal we actually don't initialize toolchain at all. I don't why but it seems that calling exec:exec directly don't run any maven phase.

@janweinschenker's example is good, but personally I don't want to duplicate paths in toolchains.xml and my pom.xml.

My workaround is to explicitly point to the maven phase when internal executable is ready and than run exec:exec goal.

mvn compile exec:exec

en0ne avatar Oct 05 '18 00:10 en0ne

In addition I want to say that maybe we had misunderstanding with maven-exec-plugin use-case. I think that exec:exec goal is to run any executable in separate process, exec:java goal is to run any executable in the same maven process for some cases when we need optimizations or access to environment of maven process. Anyway executable can be ready on different maven phases and that's why direct call of mvn exec:exec don't run any phase. This is our responsibility to describe when we need to run this goal.

en0ne avatar Oct 05 '18 00:10 en0ne

I have the same issue. Is there any solution?

nmatt avatar Aug 02 '20 22:08 nmatt

Still facing this issue

abdullah-jaffer avatar Apr 28 '22 05:04 abdullah-jaffer

It seems exec:exec picks up Java from toolchain plugin, but exec:java still does not care about toolchain.

https://stackoverflow.com/questions/73830548/maven-exec-plugin-with-toolchain-can-not-enable-preview-features

hantsy avatar Oct 13 '22 00:10 hantsy

The exec:java goal needs to support a forked mode that supports the Toolchain specified JDK if the java goal claims to run in the same runtime context as the Maven JDK - otherwise it should just use the Toolchain specified JDK always.

deepakab03 avatar Nov 07 '22 10:11 deepakab03