Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Installing JRE programatically
Installing JRE programatically [message #1348025] Sun, 11 May 2014 16:54
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
Hi

this is not a question. It took me quit a while to figure this out, so i thougth this could be useful for someone else...

Plugin dependency: org.eclipse.jdt.launching

void installJre(String name, String path) throws CoreException, IOException {
		
	File installLocation = new File(path).getAbsoluteFile().getCanonicalFile();
		
	IVMInstallType instType = null;
	for( IVMInstallType i : JavaRuntime.getVMInstallTypes()){
		if( i.getName().equals( "Standard VM" )){
			instType = i;
			break;
		}
	}
	for( IVMInstall vm : instType.getVMInstalls()){
		if( vm.getInstallLocation().equals(installLocation) ){
			System.err.printf("JRE already installed: name=%s, path=%\n", name, path );
			return;
		}
	}
		
	IStatus valState = instType.validateInstallLocation(installLocation);
	if( valState != null && !valState.isOK() ){
		System.err.printf("JRE path is not valid: name=%s, path=%\n", name, path );
		return;
	}
		
	VMStandin vmStandin = new VMStandin(instType, name);
	vmStandin.setName(name);
	vmStandin.setInstallLocation(installLocation);

	IVMInstall vmReal = vmStandin.convertToRealVM();
	JavaRuntime.setDefaultVMInstall(vmReal, new NullProgressMonitor());
	JavaRuntime.saveVMConfiguration();
}


cu
Frank
Previous Topic:Can convert apk to eclipse?
Next Topic:How to use default and static methods on interfaces w Eclipse Kepler / JDK 8?
Goto Forum:
  


Current Time: Thu May 30 17:20:33 GMT 2024

Powered by FUDForum. Page generated in 0.03967 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top