4
votes

Given the Bluemix announcement that java 8 is supported. What do I need to do to get my java 8 app compiling in the IBM Bluesmix build pipeline (jazzhub build and deploy).

I have set the java8 environment variable and restaged the app using the following:

cf set-env <myApp> JBP_CONFIG_IBMJDK "version: 1.8.+"
cf restage <myApp>

The specific 'builder type' I am using is 'Maven' and the failures I receive are around the new date and time classes in java8.

[ERROR] <...>/services/TestHelperService.java:[3,17] package java.time does not exist
[ERROR] <...>/services/TestHelperService.java:[37,17] cannot find symbol
[ERROR] symbol:   class LocalDateTime
[ERROR] location: class <...>.services.TestHelperService
4

4 Answers

10
votes

To use Java 8 you need to change the JAVA_HOME environment variable in the build shell command:

export JAVA_HOME=~/java8

For example:

#!/bin/bash
#export JAVA_HOME=~/java8 - Bluemix have changed the java8 location
export JAVA_HOME=/opt/IBM/java8
mvn -B package
1
votes

I also wanted to use Java8 in Bluemix Jazz build pipeline. Just changing $JAVA_HOME didn't work for me. I had to update the $PATH as well.

export JAVA_HOME=/opt/IBM/java8
export PATH=$JAVA_HOME/bin:$PATH

After that maven was run on java8.

0
votes

Hi this solution does not work for me here is my build script

#!/bin/bash
echo "Java Home before $JAVA_HOME"
export JAVA_HOME=~/java8
echo "Java Home after $JAVA_HOME"
#mvn -B package -DskipTests
#mvn -B package

And here is the console output as you can see JAVA_HOME is not modified after "export" command.

Checking out Revision 86514c6dc277b6903fcd6f51ca7c97ea733b1d42 (detached)
[ba6eba91-33a3-4b67-8efd-48962cf063ba] $ /bin/bash /tmp/hudson7007424628517212775.sh
Java Home before /home/jenkins/java
Java Home after /home/jenkins/java
Base artifact directory /home/jenkins/workspace/e92a4db8-6702-d006-0cdc-2a827a4e78a5/ba6eba91-33a3-4b67-8efd-48962cf063ba/target does not exist or is not a valid directory.
[xUnit] [INFO] - Starting to record.
[xUnit] [INFO] - Processing JUnit
[xUnit] [INFO] - [JUnit] - No test report file(s) were found with the pattern 'target/surefire-reports/TEST-*.xml' relative to '/home/jenkins/workspace/e92a4db8-6702-d006-0cdc-2a827a4e78a5/ba6eba91-33a3-4b67-8efd-48962cf063ba' for the testing framework 'JUnit'.  Did you enter a pattern relative to the correct directory?  Did you generate the result report(s) for 'JUnit'?
[xUnit] [ERROR] - No test reports found for the metric 'JUnit' with the resolved pattern 'target/surefire-reports/TEST-*.xml'. Configuration error?.
[xUnit] [INFO] - There are errors when processing test results.
[xUnit] [INFO] - Skipping tests recording.
Finished: SUCCESS
0
votes

I can confirm that setting JAVA_HOME to /opt/IBM/java8 in the build script does work (tried out on 2016-05-04):

#!/bin/bash
 echo "Java home before: $JAVA_HOME"
 export JAVA_HOME=/opt/IBM/java8
 echo "Java home after: $JAVA_HOME"
 mvn -B package

This results in the output:

Java home before: /opt/IBM/java
Java home after: /opt/IBM/java8

As noted before, the deploy stage must either have JBP_CONFIG_IBMJDK set to "version: 1.8.+" (cf set-env myApp JBP_CONFIG_IBMJDK "version: 1.8.+" or line in env: section of manifest.yml) or (that's what I do) you need to define buildpack: java_buildpack in manifest.yml. Since May 2015, java_buildpack uses to JDK8.

Last thing to be aware of is to change source version of maven-compiler-plugin in pom.xml, of course -- but that's not Bluemix-specific.

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>(whatever version is current)</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
    [...]
  </build>
  [...]
</project>