Fixed error messages for when a single file source code file is used for java execution, and that file is ALSO on the classpath...

master Version_3.5
Robinson 2022-01-20 16:14:14 +01:00
parent 54b0006b59
commit a123392425
No known key found for this signature in database
GPG Key ID: 8E7DB78588BD6F5C
3 changed files with 78 additions and 8 deletions

View File

@ -25,6 +25,21 @@ This project is powerful but still simple to use. By using a single class **Exec
the user gets the functionality from both **java.lang.ProcessBuilder** and [Apache Commons Exec](http://commons.apache.org/proper/commons-exec/), along with the ability to fork the currently running JVM process and remotely execute commands via SSH.
NOTE: If you are launching a JVM process (or running java manually setting options), and using the java11+ feature of executing as a "single file
source code", and you ALSO have that class file on the classpath, you **WILL** get the following error:
```error: class found on application class path ....```
What this *REALLY* means is:
```
"error: A compiled class <fully qualified class name> already exists on
the application classpath and as a result the same class cannot be used
as a source for launching single-file source code program".
```
https://mail.openjdk.java.net/pipermail/jdk-dev/2018-June/001438.html
&nbsp;
&nbsp;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2020 dorkbox, llc
* Copyright 2022 dorkbox, llc
* Copyright (C) 2014 ZeroTurnaround <support@zeroturnaround.com>
* Contains fragments of code from Apache Commons Exec, rights owned
@ -64,15 +64,28 @@ import java.util.concurrent.*
*
* The default configuration for executing a process is following:
*
*
* * Process is not automatically destroyed on VM exit.
* * Error stream is redirected to its output stream. Use [.redirectErrorStream] to override it.
* * Output stream is pumped to a [NopOutputStream], Use [.streams], [.redirectOutput],
* or any of the `redirectOutputAs*` methods.to override it.
* * Output stream is pumped to a [NopOutputStream], Use [.streams], [.redirectOutput], or any of the `redirectOutputAs*` methods.to override it.
* * Any exit code is allowed. Use [.exitValues] to override it.
* * In case of timeout or cancellation [Process.destroy] is invoked.
*
* @author Rein Raudjärv
*
* NOTE: If you are launching using the same classpath as before, and you set the main-classpath to be executed as a
* "single file source code" file via java11+, YOU CAN GET THE FOLLOWING ERROR.
*
* "error: class found on application class path .... "
*
* What this REALLY means is:
*
* "error: A compiled class <fully qualified class name> already exists on
* the application classpath and as a result the same class cannot be used
* as a source for launching single-file source code program".
*
* https://mail.openjdk.java.net/pipermail/jdk-dev/2018-June/001438.html
*
*
* @author Rein Raudjärv, Nathan Robinson
* @see ProcessResult
*/
@Suppress("MemberVisibilityCanBePrivate", "unused")

View File

@ -26,6 +26,20 @@ import java.util.concurrent.*
/**
* Options for configuring a process to run using the same JVM as the currently launched jvm
*
*
* NOTE: If you are launching using the same classpath as before, and you set the main-classpath to be executed as a
* "single file source code" file via java11+, YOU CAN GET THE FOLLOWING ERROR.
*
* "error: class found on application class path .... "
*
* What this REALLY means is:
*
* "error: A compiled class <fully qualified class name> already exists on
* the application classpath and as a result the same class cannot be used
* as a source for launching single-file source code program".
*
* https://mail.openjdk.java.net/pipermail/jdk-dev/2018-June/001438.html
*/
class JvmExecOptions(private val executor: Executor, private val javaExecutable: String? = null) {
@ -115,7 +129,21 @@ class JvmExecOptions(private val executor: Executor, private val javaExecutable:
}
/**
* Copies the original JVM classpath in this newly created JVM
* Copies the original JVM classpath in this newly created JVM.
*
*
* NOTE: If you are launching using the same classpath as before, and you set the main-classpath to be executed as a
* "single file source code" file via java11+, YOU CAN GET THE FOLLOWING ERROR.
*
* "error: class found on application class path .... "
*
* What this REALLY means is:
*
* "error: A compiled class <fully qualified class name> already exists on
* the application classpath and as a result the same class cannot be used
* as a source for launching single-file source code program".
*
* https://mail.openjdk.java.net/pipermail/jdk-dev/2018-June/001438.html
*/
fun cloneClasspath(): JvmExecOptions {
this.cloneClasspath = true
@ -123,8 +151,22 @@ class JvmExecOptions(private val executor: Executor, private val javaExecutable:
}
/**
* Set the main class to launch (optional, as a JAR can have this in the manifest)
*/
* Set the main class to launch (optional, as a JAR can have this in the manifest).
*
*
* NOTE: If you are launching using the same classpath as before, and you set the main-classpath to be executed as a
* "single file source code" file via java11+, YOU CAN GET THE FOLLOWING ERROR.
*
* "error: class found on application class path .... "
*
* What this REALLY means is:
*
* "error: A compiled class <fully qualified class name> already exists on
* the application classpath and as a result the same class cannot be used
* as a source for launching single-file source code program".
*
* https://mail.openjdk.java.net/pipermail/jdk-dev/2018-June/001438.html
*/
fun setMainClass(mainClass: String): JvmExecOptions {
// we have to normalize the main class path.
this.mainClass = mainClass