diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java index c13a543c6..a909ef918 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java @@ -92,7 +92,7 @@ public abstract class StartDebugMojoSupport extends ServerFeatureSupport { protected Map bootstrapMavenProps = new HashMap(); protected Map envMavenProps = new HashMap(); - protected List jvmMavenPropNames = new ArrayList(); + protected List jvmMavenPropNames = new ArrayList(); // only used for tracking overriding properties - not included in the generated jvm.options file protected List jvmMavenPropValues = new ArrayList(); protected Map varMavenProps = new HashMap(); protected Map defaultVarMavenProps = new HashMap(); @@ -821,21 +821,21 @@ private void loadLibertyConfigFromProperties(Properties props) { getLog().debug("Processing Liberty configuration from property with key "+key+" and value "+value); switch (propType) { - case ENV: envMavenProps.put(suffix, value); - break; - case BOOTSTRAP: bootstrapMavenProps.put(suffix, value); - break; - case JVM: if (jvmMavenPropNames.contains(suffix)) { + case ENV: envMavenProps.put(suffix, value); + break; + case BOOTSTRAP: bootstrapMavenProps.put(suffix, value); + break; + case JVM: if (jvmMavenPropNames.contains(suffix)) { int index = jvmMavenPropNames.indexOf(suffix); getLog().debug("Remove duplicate property with name: "+suffix+" at position: "+index); jvmMavenPropNames.remove(index); jvmMavenPropValues.remove(index); - } - jvmMavenPropNames.add(suffix); - jvmMavenPropValues.add(value); - break; - case VAR: varMavenProps.put(suffix, value); - break; + } + jvmMavenPropNames.add(suffix); // need to keep track of names so that a system prop can override a project prop + jvmMavenPropValues.add(value); + break; + case VAR: varMavenProps.put(suffix, value); + break; case DEFAULTVAR: defaultVarMavenProps.put(suffix, value); break; } @@ -952,24 +952,21 @@ private void writeServerEnvProperties(File file, Map mavenProper } // Remove any duplicate entries in the passed in List - protected List getUniqueValues(List options) { - List uniqueOptions = new ArrayList (); - if (options == null) { - return uniqueOptions; - } - if (options.isEmpty()) { - return options; + protected List getUniqueValues(List values) { + List uniqueValues = new ArrayList (); + if (values == null) { + return uniqueValues; } - for (String nextOption : options) { - // by removing the option first, it ensures this one is last and not a duplicate - nothing happens if the option is not there - if (uniqueOptions.contains(nextOption)) { - getLog().debug("Remove duplicate option: "+nextOption+" at position: "+uniqueOptions.indexOf(nextOption)); + for (String nextValue : values) { + // by removing a matching existing value, it ensures there will not be a duplicate and that this current one will appear later in the List + if (uniqueValues.contains(nextValue)) { + getLog().debug("Remove duplicate value: "+nextValue+" at position: "+uniqueValues.indexOf(nextValue)); } - uniqueOptions.remove(nextOption); - uniqueOptions.add(nextOption); + uniqueValues.remove(nextValue); // has no effect if the value is not present + uniqueValues.add(nextValue); } - return uniqueOptions; + return uniqueValues; } // One of the passed in Lists must be not null and not empty @@ -982,7 +979,8 @@ private void writeJvmOptions(File file, List options, List maven combinedJvmOptions = uniqueMavenProps; } else { combinedJvmOptions = new ArrayList (); - // add the maven properties first so that they do not take precedence over the options specified with jvmOptions + // add the maven properties (which consist of both project properties and system properties) first, + // so that they do not take precedence over the options specified with jvmOptions config parameter combinedJvmOptions.addAll(uniqueMavenProps); combinedJvmOptions.removeAll(uniqueOptions); // remove any exact duplicates before adding all the jvmOptions combinedJvmOptions.addAll(uniqueOptions);