Skip to content

Issue #17766 - change classpath from command line to environment variable when forking #24320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -62,6 +63,8 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {

private static final String SPRING_BOOT_APPLICATION_CLASS_NAME = "org.springframework.boot.autoconfigure.SpringBootApplication";

private static final String CLASSPATH_ENV_VAR_KEY = "CLASSPATH";

/**
* The Maven project.
* @since 1.0.0
Expand Down Expand Up @@ -290,7 +293,7 @@ private void doRunWithForkedJvm(String startClassName) throws MojoExecutionExcep
List<String> args = new ArrayList<>();
addAgents(args);
addJvmArgs(args);
addClasspath(args);
addClasspath();
args.add(startClassName);
addArgs(args);
runWithForkedJvm((this.workingDirectory != null) ? this.workingDirectory : this.project.getBasedir(), args,
Expand Down Expand Up @@ -410,7 +413,7 @@ private void addActiveProfileArgument(RunArguments arguments) {
}
}

private void addClasspath(List<String> args) throws MojoExecutionException {
private void addClasspath() throws MojoExecutionException {
try {
StringBuilder classpath = new StringBuilder();
for (URL ele : getClassPathUrls()) {
Expand All @@ -422,8 +425,18 @@ private void addClasspath(List<String> args) throws MojoExecutionException {
if (getLog().isDebugEnabled()) {
getLog().debug("Classpath for forked process: " + classpath);
}
args.add("-cp");
args.add(classpath.toString());
if (this.environmentVariables == null) {
this.environmentVariables = new HashMap<>();
}
StringBuilder interim = new StringBuilder();
if (this.environmentVariables.containsKey(CLASSPATH_ENV_VAR_KEY)) {
interim.append(this.environmentVariables.get(CLASSPATH_ENV_VAR_KEY));
if (!interim.toString().endsWith(File.pathSeparator)) {
interim.append(File.pathSeparator);
}
}
interim.append(classpath);
this.environmentVariables.put(CLASSPATH_ENV_VAR_KEY, interim.toString());
}
catch (Exception ex) {
throw new MojoExecutionException("Could not build classpath", ex);
Expand Down