I'm using Maven Embedder version 3.9.3 in a project that dynamically creates, compiles, and deploys a Java archive. This works fine on my Mac, but when I try to run it on a Windows machine I run into problems. The Windows machine has two JDKs installed, one of which I have permission to modify, the other one which I don't.
When I run Maven from the command line it's picking up the JDK I can modify (verified using mvn -version
):
Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)
Maven home: C:\Users\IPage\apache-maven-3.8.7
Java version: 11.0.16.1, vendor: Amazon.com Inc., runtime: C:\Users\IPage\jdk11.0.16_9
Default locale: en_GB, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
However, when the Maven Embedder runs, it picks up the other JDK (verified using -X
as a parameter to the MavenCli.doMain
method):
Apache Maven 3.9.3 (21122926829f1ead511c958d89bd2f672198ae9f)
Maven home: <unknown Maven home>
Java version: 11.0.17, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-11.0.17
Default locale: en_GB, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
The issue is that the build process needs to download dependencies from a Nexus repo that uses an untrusted certificate chain. I've installed the certificate on the JDK I have access to, but can't install it on the other JDK. Because Maven Embedder uses this other JDK, the dependency download fails with the classic "PKIX path building failed" error.
My Windows account's PATH
variable contains the path to the JDK that I can modify, which is presumably why the correct one is picked up when I run mvn
from the command line. But why is Maven Embedder choosing the wrong one, as is there a way I can specify it? The system's PATH
variable is pointing to the wrong JDK, but I don't have permission to change that.
I've tried specifying maven.comiler.executable=true
and maven.compiler.executable=/path/to/correct/javac
as parameters for MavenCli.doMain
, but the results were exactly the same.