You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ma...@apache.org on 2019/04/16 14:55:13 UTC

[nifi] branch master updated: NIFI-5820 NiFi built on Java 8 can run on Java 11 Updated RunNiFi.java to add libs needed to run on Java 11 when it is the detected runtime java version and grant access to the necessary module (java.xml.bind) when running on Java 9 or 10 Added dependencies/includes/excludes to nifi-assembly configurations for enabling NiFi to run on Java 11

This is an automated email from the ASF dual-hosted git repository.

markap14 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/master by this push:
     new 2453c36  NIFI-5820 NiFi built on Java 8 can run on Java 11 Updated RunNiFi.java to add libs needed to run on Java 11 when it is the detected runtime java version and grant access to the necessary module (java.xml.bind) when running on Java 9 or 10 Added dependencies/includes/excludes to nifi-assembly configurations for enabling NiFi to run on Java 11
2453c36 is described below

commit 2453c36710b4752c653752fe2991771a92a13de8
Author: Jeff Storck <jt...@gmail.com>
AuthorDate: Thu Nov 15 18:38:02 2018 -0500

    NIFI-5820 NiFi built on Java 8 can run on Java 11
    Updated RunNiFi.java to add libs needed to run on Java 11 when it is the detected runtime java version and grant access to the necessary module (java.xml.bind) when running on Java 9 or 10
    Added dependencies/includes/excludes to nifi-assembly configurations for enabling NiFi to run on Java 11
    
    This closes #3174.
    
    Signed-off-by: Mark Payne <ma...@hotmail.com>
---
 nifi-assembly/pom.xml                              | 48 ++++++++++++++++++++++
 nifi-assembly/src/main/assembly/common.xml         | 18 ++++++++
 nifi-assembly/src/main/assembly/dependencies.xml   |  8 ++++
 .../java/org/apache/nifi/bootstrap/RunNiFi.java    | 22 +++++++++-
 4 files changed, 94 insertions(+), 2 deletions(-)

diff --git a/nifi-assembly/pom.xml b/nifi-assembly/pom.xml
index 164b01a..5f041f9 100755
--- a/nifi-assembly/pom.xml
+++ b/nifi-assembly/pom.xml
@@ -745,6 +745,34 @@ language governing permissions and limitations under the License. -->
             <version>1.10.0-SNAPSHOT</version>
             <type>nar</type>
         </dependency>
+
+        <!-- dependencies for jaxb/activation/annotation for running NiFi on Java 11 -->
+        <!-- TODO: remove these once minimum Java version is 11 -->
+        <dependency>
+            <groupId>javax.xml.bind</groupId>
+            <artifactId>jaxb-api</artifactId>
+            <version>2.3.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.sun.xml.bind</groupId>
+            <artifactId>jaxb-impl</artifactId>
+            <version>2.3.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.sun.xml.bind</groupId>
+            <artifactId>jaxb-core</artifactId>
+            <version>2.3.0</version>
+        </dependency>
+        <dependency>
+            <groupId>javax.annotation</groupId>
+            <artifactId>javax.annotation-api</artifactId>
+            <version>1.3.2</version>
+        </dependency>
+        <dependency>
+            <groupId>javax.activation</groupId>
+            <artifactId>javax.activation-api</artifactId>
+            <version>1.2.0</version>
+        </dependency>
     </dependencies>
     <profiles>
         <profile>
@@ -992,6 +1020,13 @@ language governing permissions and limitations under the License. -->
                                                     which are also not in bootstrap -->
                                                     <exclude>org.apache.nifi:nifi-resources</exclude>
                                                     <exclude>org.apache.nifi:nifi-docs</exclude>
+                                                    <!-- exclude jaxb/activation/annotation libs from lib, they'll be included in the java11 subdir -->
+                                                    <!-- TODO: remove these once minimum Java version is 11 -->
+                                                    <exclude>javax.xml.bind:jaxb-api</exclude>
+                                                    <exclude>com.sun.xml.bind:jaxb-impl</exclude>
+                                                    <exclude>com.sun.xml.bind:jaxb-core</exclude>
+                                                    <exclude>javax.activation:javax.activation-api</exclude>
+                                                    <exclude>javax.annotation:javax.annotation-api</exclude>
                                                 </excludes>
                                             </dependency>
                                         </mapping>
@@ -1031,6 +1066,19 @@ language governing permissions and limitations under the License. -->
                                             </dependency>
                                         </mapping>
                                         <mapping>
+                                            <!-- TODO: remove this mapping once minimum Java version is 11 -->
+                                            <directory>/opt/nifi/nifi-${project.version}/lib/java11</directory>
+                                            <dependency>
+                                                <includes>
+                                                    <include>javax.xml.bind:jaxb-api</include>
+                                                    <include>com.sun.xml.bind:jaxb-impl</include>
+                                                    <include>com.sun.xml.bind:jaxb-core</include>
+                                                    <include>javax.activation:javax.activation-api</include>
+                                                    <include>javax.annotation:javax.annotation-api</include>
+                                                </includes>
+                                            </dependency>
+                                        </mapping>
+                                        <mapping>
                                             <directory>/opt/nifi/nifi-${project.version}/docs</directory>
                                             <sources>
                                                 <source>
diff --git a/nifi-assembly/src/main/assembly/common.xml b/nifi-assembly/src/main/assembly/common.xml
index cad953d..e22d566 100644
--- a/nifi-assembly/src/main/assembly/common.xml
+++ b/nifi-assembly/src/main/assembly/common.xml
@@ -31,6 +31,24 @@
             </includes>
         </dependencySet>
 
+        <!-- Write out the bootstrap libs for java11 to its own dir -->
+        <!-- TODO: remove this dependency set once minimum Java version is 11 -->
+        <dependencySet>
+            <scope>runtime</scope>
+            <useProjectArtifact>false</useProjectArtifact>
+            <outputDirectory>lib/java11</outputDirectory>
+            <directoryMode>0770</directoryMode>
+            <fileMode>0664</fileMode>
+            <useTransitiveFiltering>true</useTransitiveFiltering>
+            <includes>
+                <include>javax.xml.bind:jaxb-api</include>
+                <include>com.sun.xml.bind:jaxb-impl</include>
+                <include>com.sun.xml.bind:jaxb-core</include>
+                <include>javax.activation:javax.activation-api</include>
+                <include>javax.annotation:javax.annotation-api</include>
+            </includes>
+        </dependencySet>
+
         <!-- Write out the conf directory contents -->
         <dependencySet>
             <scope>runtime</scope>
diff --git a/nifi-assembly/src/main/assembly/dependencies.xml b/nifi-assembly/src/main/assembly/dependencies.xml
index c6dd23c..f804e7b 100644
--- a/nifi-assembly/src/main/assembly/dependencies.xml
+++ b/nifi-assembly/src/main/assembly/dependencies.xml
@@ -35,6 +35,14 @@
                 <exclude>nifi-bootstrap</exclude>
                 <exclude>nifi-resources</exclude>
                 <exclude>nifi-docs</exclude>
+
+                <!-- exclude jaxb/activation/annotation libs from lib, they'll be included in the java11 subdir -->
+                <!-- TODO: remove these once minimum Java version is 11 -->
+                <exclude>javax.xml.bind:jaxb-api</exclude>
+                <exclude>com.sun.xml.bind:jaxb-impl</exclude>
+                <exclude>com.sun.xml.bind:jaxb-core</exclude>
+                <exclude>javax.activation:javax.activation-api</exclude>
+                <exclude>javax.annotation:javax.annotation-api</exclude>
             </excludes>
         </dependencySet>
     </dependencySets>
diff --git a/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java b/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java
index 953cdce..78e7019 100644
--- a/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java
+++ b/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java
@@ -49,6 +49,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Objects;
 import java.util.Properties;
 import java.util.Set;
 import java.util.concurrent.ExecutorService;
@@ -993,6 +994,23 @@ public class RunNiFi {
             cpFiles.add(file.getAbsolutePath());
         }
 
+        String runtimeJavaVersion = System.getProperty("java.version");
+        defaultLogger.info("Runtime Java version: {}", runtimeJavaVersion);
+        if (Integer.parseInt(runtimeJavaVersion.substring(0, runtimeJavaVersion.indexOf('.'))) >= 11) {
+            /* If running on Java 11 or greater, add the JAXB/activation/annotation libs to the classpath.
+             *
+             * TODO: Once the minimum Java version requirement of NiFi is 11, this processing should be removed.
+             * JAXB/activation/annotation will be added as an actual dependency via pom.xml.
+             */
+            final String libJava11Filename = replaceNull(props.get("lib.dir"), "./lib").trim() + "/java11";
+            File libJava11Dir = getFile(libJava11Filename, workingDir);
+            if (libJava11Dir.exists()) {
+                for (final File file : Objects.requireNonNull(libJava11Dir.listFiles((dir, filename) -> filename.toLowerCase().endsWith(".jar")))) {
+                    cpFiles.add(file.getAbsolutePath());
+                }
+            }
+        }
+
         final StringBuilder classPathBuilder = new StringBuilder();
         for (int i = 0; i < cpFiles.size(); i++) {
             final String filename = cpFiles.get(i);
@@ -1032,8 +1050,8 @@ public class RunNiFi {
         cmd.add("-Dnifi.bootstrap.listen.port=" + listenPort);
         cmd.add("-Dapp=NiFi");
         cmd.add("-Dorg.apache.nifi.bootstrap.config.log.dir=" + nifiLogDir);
-        if (!System.getProperty("java.version").startsWith("1.")) {
-            // running on Java 9+, java.xml.bind module must be made available
+        if (runtimeJavaVersion.startsWith("9") || runtimeJavaVersion.startsWith("10")) {
+            // running on Java 9 or 10, internal module java.xml.bind module must be made available
             cmd.add("--add-modules=java.xml.bind");
         }
         cmd.add("org.apache.nifi.NiFi");