[jboss-jira] [JBoss JIRA] (WFCORE-4329) The launcher API may incorrectly assume the JVM is a non-modular JVM
James Perkins (Jira)
issues at jboss.org
Thu Feb 14 19:05:00 EST 2019
[ https://issues.jboss.org/browse/WFCORE-4329?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13695763#comment-13695763 ]
James Perkins commented on WFCORE-4329:
---------------------------------------
Note that for a JRE the {{release}} file does not exist. It's only in the JDK. This would cause Java 8 to always launch a new process to validate whether this is a modular JVM or not.
> The launcher API may incorrectly assume the JVM is a non-modular JVM
> --------------------------------------------------------------------
>
> Key: WFCORE-4329
> URL: https://issues.jboss.org/browse/WFCORE-4329
> Project: WildFly Core
> Issue Type: Bug
> Components: Launcher
> Reporter: James Perkins
> Assignee: James Perkins
> Priority: Major
>
> The launcher API checks the {{$JAVA_HOME/jmods}} directory and if missing assumes it's a non-modular JVM, e.g. Java 8 or lower. In some cases this directory does not exist. We need a better way to determine the JVM version.
> It's done in the wildfly-maven-plugin like:
> {code}
> /**
> * Checks to see if the {@code javaHome} is a modular JVM.
> *
> * @param javaHome the Java Home if {@code null} an attempt to discover the Java Home will be done
> *
> * @return {@code true} if this is a modular environment
> */
> public static boolean isModularJvm(final Path javaHome) {
> boolean result;
> final List<String> cmd = new ArrayList<>();
> cmd.add(getJavaCommand(javaHome));
> cmd.add("--add-modules=java.se");
> cmd.add("-version");
> final ProcessBuilder builder = new ProcessBuilder(cmd);
> Process process = null;
> Path stdout = null;
> try {
> // Create a temporary file for stdout
> stdout = Files.createTempFile("stdout", ".txt");
> process = builder.redirectErrorStream(true)
> .redirectOutput(stdout.toFile()).start();
> if (process.waitFor(1, TimeUnit.SECONDS)) {
> result = process.exitValue() == 0;
> } else {
> if (LOGGER.isDebugEnabled()) {
> LOGGER.debug(getStdoutMessage("The process timed out waiting for the response.", stdout));
> }
> result = false;
> }
> } catch (IOException | InterruptedException e) {
> if (LOGGER.isDebugEnabled()) {
> LOGGER.debug(getStdoutMessage("The process ended in error.", stdout), e);
> }
> result = false;
> } finally {
> if (process != null && process.isAlive()) {
> process.destroyForcibly();
> }
> if (stdout != null) {
> try {
> Files.deleteIfExists(stdout);
> } catch (IOException ignore) {
> }
> }
> }
> return result;
> }
> {code}
> This works, however requires a new process to be created and launched which is not ideal.
> It does look like there might be a {{$JAVA_HOME/release}} file which looks like a properties file with the {{JAVA_VERSION}} property. However we need to determine if all vendors include this file.
--
This message was sent by Atlassian Jira
(v7.12.1#712002)
More information about the jboss-jira
mailing list