8 Replies Latest reply on Jun 16, 2014 3:59 PM by remi.bantos

    Openshift Wildfly 8.1 cartridge - JDK8 and maven build

    remi.bantos

      Hello,

       

      I have an issue with maven build of my application which uses JDK8 with a Wildfly 8.1 cartridge.

       

      I use QueryDSL apt-maven-plugin which performs code generation during build.

       

      This plugin seems to require JAVA_HOME to be set to the same JDK as the one used in application prior to maven build launch. (I have not been able to find a plugin configuration to declare a specific JDK use for it)

       

      Indeed, I have a language level compilation error (using a Java 8 lambda expression) that i can reproduce on my personal development environment by launching maven build with a default JDK7 installed and after having applied steps described in this post: (which describes how to configure maven build in Wildfly 8.1 cartridge to use JDK8) WildFly 8.1.0.Final on OpenShift - with JDK 8 support!

       

      I have noticed that the following maven script  is used in Openshift VM during build:

       

      export JAVA_HOME=/usr/lib/jvm/java

      export JAVACMD=$JAVA_HOME/bin/java

      export M2_HOME=/usr/share/java/apache-maven-3.0.4

      exec $M2_HOME/bin/$prog "$@"

       

      /usr/lib/jvm/java is a JDK7. So i cannot override JAVA_HOME in my application to use JDK8 installation described in this post.

       

      Here is the exception I have due to this build configuration issue:

      [INFO] --- apt-maven-plugin:1.1.1:process (default) @ catalog ---

      /var/lib/openshift/538fb4fe4382ecd4c00002c7/app-root/runtime/repo/catalog/src/main/java/org/rembx/jeeshop/catalog/CatalogItemFinder.java:45: error: illegal start of expression

              results.forEach((catalogItem) -> catalogItem.setLocalizedPresentation(locale));

                                             ^

      1 error

       

      Thanks for your help

        • 1. Re: Openshift Wildfly 8.1 cartridge - JDK8 and maven build
          ctomc

          You actually have two interesting problems right here...

           

          Build is not using JDK8 but 7 which should be fixed.

          Also you have another problem in your code, if build would be using JDK8 it would fail anyway as you are using apt-maven-plugin which uses APT tool from JDK, which was removed in JDK8.

           

          So in short, your code cannot build properly on JDK8, even when OS cartridge is fixed.

          1 of 1 people found this helpful
          • 2. Re: Openshift Wildfly 8.1 cartridge - JDK8 and maven build
            remi.bantos

            Thanks a lot for this information.

            However, when I export JAVA_HOME to oracle JDK 8 in my DEV environment, this QueryDSL plugin works properly, and maven build performs successfully

            (I have also tested it successfully on TRAVIS CI with java 8 level)

            For your information, here is the source code of this plugin: querydsl/apt-maven-plugin · GitHub

             

            So I'll be waiting for a fix on Wildfly 8.1 cartridge. Do you have any idea when it will be fixed?

             

            Thanks

            • 3. Re: Re: Openshift Wildfly 8.1 cartridge - JDK8 and maven build
              fjuma

              This doesn't seem like a cartridge bug, the build correctly uses JDK 8 when the default maven-war-plugin is used (note that even though JAVA_HOME is shown in the output as /usr/lib/jvm/java when the build is first launched, the maven.compiler.executable and maven.compiler.fork properties in the default pom.xml file ensure that JDK 8 will actually get used when building). It sounds like some additional properties just need to be added to your apt-maven-plugin configuration. Does adding the following properties work for you?

               

              <configuration>
              ...
                  <fork>true</fork>
                  <executable>${env.OPENSHIFT_WILDFLY_DIR}usr/lib/jvm/jdk1.8.0_05/bin/javac</executable>
              </configuration>
              
              • 4. Re: Openshift Wildfly 8.1 cartridge - JDK8 and maven build
                remi.bantos

                Hello Farah,

                 

                I had reproduced this issue in my own development environment (not int Openshift) using a JDK7 to run maven and after having performed all the steps described in your blog WildFly 8.1.0.Final on OpenShift - with JDK 8 support! to use JDK8 with the fork option.

                I've figured out that i really need JAVA_HOME to be set to JDK8 for this plugin be correctly working: querydsl/apt-maven-plugin · GitHub

                As use of JDK7 is hardcoded in mvn command script, i had not been able to build my application.

                 

                Several plugins, such as Surefire plugin, have a <jvm> element configuration which allows to specify a specific JDK with the forking option. However, this QueryDSL plugin i use does not seem to have such a configuration.

                 

                Here is an extract of Surefire documentation which describes <jvm> attribute.

                jvmString2.1Option to specify the jvm (or path to the java executable) to use with the forking options. For the default, the jvm will be a new instance of the same VM as the one used to run Maven. JVM settings are not inherited from MAVEN_OPTS.
                User property is: jvm.

                 

                Thus, by default, this QueryDSL plugin uses the same JDK as the one specified in JAVA_HOME used by maven build.

                Therefore, i would really need a way to override this JAVA_HOME setting for maven build in Wildfly 8.1 cartridge.

                 

                Thanks,

                Remi

                • 5. Re: Re: Openshift Wildfly 8.1 cartridge - JDK8 and maven build
                  fjuma

                  The properties mentioned in the blog post pertain to the maven plugin configured in the default pom.xml file. If the plugin you're using doesn't support a similar way to specify the JDK version using a fork option, it doesn't look like there's a way to get the build to work right now. (Note that the mvn script that hardcodes JAVA_HOME to JDK 7 is an OpenShift script that's not owned by the WildFly cartridge so there isn't really a way to override it. Instead, when using the maven plugin configured in the default pom.xml file, the maven.compiler.executable and maven.compiler.fork properties allow the correct JDK version to get used.)

                   

                  As a workaround for now, you could build your WAR locally and push it to your git repo. Instructions for this can be found below (see "Method 2"):

                  http://openshift.github.io/documentation/oo_cartridge_guide.html#layout-and-deployment-options

                  1 of 1 people found this helpful
                  • 6. Re: Openshift Wildfly 8.1 cartridge - JDK8 and maven build
                    remi.bantos

                    Ok, i'll be waiting for a change on OpenShift maven build, to run it with JAVA_HOME exported to something else than JDK7, as i would like to use OpenShift build functionnality.

                    Thanks

                    • 7. Re: Openshift Wildfly 8.1 cartridge - JDK8 and maven build
                      fjuma

                      The OpenShift team will update the mvn script once they provide JDK 8 support. You can create a bugzilla issue against OpenShift Online though if you'd like a way to override JAVA_HOME:

                       

                      https://bugzilla.redhat.com/enter_bug.cgi?product=OpenShift%20Online

                      • 8. Re: Openshift Wildfly 8.1 cartridge - JDK8 and maven build
                        remi.bantos