I'm calling javac from C# code. Originally I found its location only as follows:
protected static string JavaHome
{
get
{
return Environment.GetEnvironmentVariable("JAVA_HOME");
}
}
However, I just installed the JDK on a new computer and found that it didn't automatically set the JAVA_HOME environment variable. Requiring an environment variable is unacceptable in any Windows application for the last decade, so I need a way to find javac if the JAVA_HOME environment variable is not set:
protected static string JavaHome
{
get
{
string home = Environment.GetEnvironmentVariable("JAVA_HOME");
if (string.IsNullOrEmpty(home) || !Directory.Exists(home))
{
// TODO: find the JDK home directory some other way.
}
return home;
}
}