Exemplo n.º 1
0
JVMInfo* JVMChooser::getJvm(const tstring& javaHomePath, const tstring& binJvmDir)
{
	JVMInfo* pJvmInfo = 0;
	try
	{			
		tstring pathToJvm = javaHomePath + tstring(_T("\\bin\\")) + binJvmDir + tstring(_T("\\jvm.dll"));
		if( LocalUtilities::fileExists(pathToJvm) )
		{
			pJvmInfo = new JVMInfo();
			pJvmInfo->setJvmPath(pathToJvm);
			pJvmInfo->setJavaHomePath(javaHomePath);
			return pJvmInfo;
		}
			
		pathToJvm = javaHomePath + tstring(_T("\\jre\\bin\\")) + binJvmDir + tstring(_T("\\jvm.dll"));
		if( LocalUtilities::fileExists(pathToJvm) )
		{
			pJvmInfo = new JVMInfo();
			pJvmInfo->setJvmPath(pathToJvm);
			pJvmInfo->setJavaHomePath(javaHomePath + tstring(_T("\\jre")));
			return pJvmInfo;
		}			
	}
	catch(...)
	{
		DEBUG_SHOW( _T("Exception in JVMChooser.getJvm()") );
		ErrHandler::severeError( _T("Error while getting the JVM from the Java home path and JVM type.") );
	}
	return 0;
}
Exemplo n.º 2
0
void WindowsRegistry::addAllJreJvms(vector<JVMInfo>* pVecJvmInfo, const tstring& regKey)
{
	try
	{
		LONG result;
		HKEY hKey;

		result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,regKey.c_str(),0,KEY_READ,&hKey);
		if (result != ERROR_SUCCESS)
		{
			// key may not exist so exit
			return;
		}

		TCHAR lpName[MAX_PATH];

		for (DWORD index = 0, result = ERROR_SUCCESS; result == ERROR_SUCCESS; index++) 
		{ 
			DWORD lpcName = MAX_PATH;
			result = RegEnumKeyEx(hKey, 
                     index, 
                     lpName, 
                     &lpcName, 
                     NULL, 
                     NULL, 
                     NULL, 
                     NULL); 

			if( result == ERROR_SUCCESS ) 
			{
				tstring dirName(lpName);	
				if( dirName.empty() )
				{
					continue;
				}

				tstring fullKeyPath = regKey + tstring(_T("\\")) + dirName;

				DEBUG_SHOW( tstring(_T("fullKeyPath=")) + fullKeyPath );
				tstring& javaHome = getStringValue(fullKeyPath, _T("JavaHome"));
				if( javaHome.empty() )
				{
					continue;
				}

				JVMInfo *pJvmInfo = new JVMInfo;
				pJvmInfo->setJavaBundle(Properties::JRE_JAVA_BUNDLE);
				pJvmInfo->setJavaHomePath(javaHome);
				pJvmInfo->setVersion(dirName);

				pVecJvmInfo->push_back(*pJvmInfo);
			}
		} 

		RegCloseKey(hKey);
	}
	catch(tstring& se)
	{
		ErrHandler::severeError( se );
	}
	catch(...)
	{
		DEBUG_SHOW( _T("Exception in WindowsRegistry.addAllJreJvms()") );
		ErrHandler::severeError( _T("Error getting JVM paths from registry.") );
	}
}