Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin does not use jdk from toolchains plugin #49

Open
janweinschenker opened this issue Jul 5, 2016 · 12 comments
Open

Plugin does not use jdk from toolchains plugin #49

janweinschenker opened this issue Jul 5, 2016 · 12 comments

Comments

@janweinschenker
Copy link

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?

@khmarbaise
Copy link
Member

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

@victornoel
Copy link

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>

@khmarbaise
Copy link
Member

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...

@victornoel
Copy link

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

@janweinschenker
Copy link
Author

Hi all,

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

best regards
Jan

@mipastgt
Copy link

mipastgt commented Jul 6, 2018

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.

@en0ne
Copy link

en0ne commented Oct 5, 2018

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
Copy link

en0ne commented Oct 5, 2018

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.

@nmatt
Copy link

nmatt commented Aug 2, 2020

I have the same issue. Is there any solution?

@abdullah-jaffer
Copy link

Still facing this issue

@hantsy
Copy link

hantsy commented Oct 13, 2022

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

@deepakab03
Copy link

deepakab03 commented Nov 7, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants