MyClass.java:
package test;
public class MyClass {
public void myMethod(){
System.out.println(\"My Method Called\");
}
}
Li
SUPPLEMENT: The answer above is to set the java.home system property within the program. That works for me too, but it's not a very general solution, since you've hard-coded for one jdk version. The alternative that I'm using now is to give the full path to "java" on the command line when I run the program. Such as (consistent with examples above):
C:\\Program Files\Java\jdk1.7.0_02\jre\bin\java -cp ..\classes path.to.program.myProgram
Giving the full path to the jdk version means that's the version that's running the program, so that's the one that will be fetched with ToolProvider.getSystemJavaCompiler();