Skip to content

Commit

Permalink
NIFI-5820 NiFi built on Java 8 can run on Java 11
Browse files Browse the repository at this point in the history
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 <markap14@hotmail.com>
  • Loading branch information
jtstorck authored and markap14 committed Apr 16, 2019
1 parent d0224f7 commit 2453c36
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
48 changes: 48 additions & 0 deletions nifi-assembly/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -1030,6 +1065,19 @@ language governing permissions and limitations under the License. -->
</includes>
</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>
Expand Down
18 changes: 18 additions & 0 deletions nifi-assembly/src/main/assembly/common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
8 changes: 8 additions & 0 deletions nifi-assembly/src/main/assembly/dependencies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
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;
Expand Down Expand Up @@ -993,6 +994,23 @@ public boolean accept(final File dir, final String filename) {
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);
Expand Down Expand Up @@ -1032,8 +1050,8 @@ public boolean accept(final File dir, final String filename) {
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");
Expand Down

0 comments on commit 2453c36

Please sign in to comment.