Tweak eclipse ls packaging/launching

Take advantage of Spring boot properties launcher ability
to add tools.jar to classpath via a system property.
This commit is contained in:
Kris De Volder
2018-03-05 11:01:01 -08:00
parent 0220cf41bd
commit 13d4436254
9 changed files with 78 additions and 104 deletions

View File

@@ -18,6 +18,10 @@ import java.util.Set;
import java.util.function.Consumer;
import org.eclipse.jdt.internal.launching.StandardVMType;
import org.eclipse.ui.internal.commands.CommandService;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
@SuppressWarnings("restriction")
public class JRE {
@@ -53,11 +57,11 @@ public class JRE {
* Get a JRE, with a paired tools jar if it is needed based on current JRE version
* and whether the caller wants it.
*
* @return The tools.jar, or null if none is needed.
* @return The JRE.
* @throws MissingToolsJarException If tools jar is needed but could not be found.
* @throws MissingJava9JDKException
* @throws MissingJDKException
*/
public static JRE findJRE(boolean needJdk) throws MissingJDKException {
public static JRE findJRE(boolean needJdk) throws MissingJDKException, MissingToolsJarException {
File mainHome = new File(System.getProperty("java.home"));
if (!needJdk) {
return new JRE(mainHome, null);
@@ -151,4 +155,23 @@ public class JRE {
}
public final File javaHome;
}
/**
* Creates a 'command' that can be used to launch a executable jar
* with this jre. The tools.jar, if available, is added automatically to the classpath
* via a "-Dloader.path" argument. For this to work properly, the executable
* jar should be packaged with Spring Boot Properties loader (i.e. specify `ZIP` layout
* in the spring-boot-maven plugin configuration)
*/
public List<String> jarLaunchCommand(String jarLocation, List<String> vmargs) {
ImmutableList.Builder<String> command = ImmutableList.builder();
command.add(getJavaExecutable());
if (toolsJar!=null) {
command.add("-Dloader.path="+toolsJar);
}
command.addAll(vmargs);
command.add("-jar");
command.add(jarLocation);
return command.build();
}
}