I am compiling this class with JavaCompiler
and it gives me a compilation error if the String
that I pass to compile is this:
public class className extends classNeed{
}
But if I delete public
it works. What could I do to make it compilable with:
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
String program = code;
Iterable<? extends JavaFileObject> fileObjects;
fileObjects = getJavaSourceFromString(program);
String[] options = new String[]{"-d", contextClass.getPath()+"temp/"+pathJar+"/",
"-classpath",contextClass.getBasePath()+"WEBINF/lib/lib1.jar;
"+contextClass.getBasePath()+"WEB-INF/lib/lib2.jar"};
compiler.getTask(null, null, null, Arrays.asList(options), null, fileObjects).call();
and it still working being public?
EDIT: ERROR string:///code.java:16: class className is public, should be declared in a filed className.java
but the name is the same