JavaCompiler-生成的类无法访问生成的枚举

JavaCompiler-生成的类无法访问生成的枚举,java,enums,javacompiler,Java,Enums,Javacompiler,我正在生成类和枚举,生成的代码看起来很好。生成的枚举位于生成的类的子包中 Generated class package - com.pkg1.pkg2 Generated enum package - com.pkg1.pkg2.enums 我有一个java测试用例,类必须在其中编译。因此,我首先编译枚举。这个很好用。现在,当类的setter方法将enum作为输入参数时,测试用例失败 1) 枚举天气的示例代码: package com.pkg1.pkg2.enums; public en

我正在生成类和枚举,生成的代码看起来很好。生成的枚举位于生成的类的子包中

Generated class package - com.pkg1.pkg2
Generated enum package  - com.pkg1.pkg2.enums
我有一个java测试用例,类必须在其中编译。因此,我首先编译枚举。这个很好用。现在,当类的setter方法将enum作为输入参数时,测试用例失败

1) 枚举天气的示例代码:

package com.pkg1.pkg2.enums;

public enum Weather{

SUMMER("summer"),
WINTER("winter");

public final String value;

public Weather(String value) {
    this.value = value;
}

public String getValue() {
return value;
}

}
2) 天气类别的示例代码:

package com.pkg1.pkg2;

import com.pkg1.pkg2.enums.Weather;

public interface Weather extends CityWeather{

public void setWeather(Weather weather);

}
3) 测试用例的示例代码:

@BeforeClass
public static void beforeAllTestMethods() throws Exception {

       /* First 3 lines runs without any error */
       String enumsPath = Paths.get("").toAbsolutePath().toString()+ "com/pkg1/pkg2/enums/"
       JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
       compiler.run(null,null,null,enumsPath + "Weather.java");

       /* The below code fails.
           error: package com.pkg1.pkg2.enums does not exist
           import com.pkg1.pkg2.enums.Weather;
                                      ^ 
       */
       String classPath = Paths.get("").toAbsolutePath().toString()+ "com/pkg1/pkg2/"
       JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
       compiler.run(null,null,null,classPath + "Weather.java");

请提供任何建议。

是否可以在pom中进行任何更新,以便在类编译期间访问枚举。如果从Intellij IDE(可能是工具支持的)手动运行,并且在类编译期间可以在pom中进行任何更新以访问枚举,则会运行此测试用例。如果从Intellij IDE手动运行此测试用例(可能是工具支持的)