* compile string source code, compile failure in diagnosticsCollector get prompt information
* @ return true: compile successfully false: failed to compile
*/
Public Boolean compiler () {
//standard content manager, change into your own implementation, covering parts method
StandardJavaFileManager standardFileManager=compiler. GetStandardFileManager (diagnosticsCollector, null, null);
JavaFileManager JavaFileManager=new StringJavaFileManage (standardFileManager);
//constructs the source object
JavaFileObject JavaFileObject=new StringJavaFileObject (fullClassName sourceCode);
//specified to load classes directory
List
The options. The add (" encoding ");
The options. The add (" utf-8 ");
Options. The add (" - the classpath ");
String classPath=CustomJavaCompilerUtils. Class. GetProtectionDomain () getCodeSource (). The getLocation () getPath ();
Try {
Options. The add (URLDecoder. Decode (classPath, "utf-8"));
} the catch (Exception ex) {}
//get a compilation task
JavaCompiler.Com pilationTask task=compiler. GetTask (null, the javaFileManager diagnosticsCollector, options, null, Arrays. The asList (javaFileObject));
The return of task. The call ();
}
Because the class references to other classes, local operation no problem, publish server will prompt can not find, consult everybody a great god, and is there a way to solve, thank you?
CodePudding user response:
Server needs to consider the path and permissions, general path is not the same as Windows, Linux server and some files need to be manually chmod authorization, and character set may be different, there will be garbled,CodePudding user response:
Are you sure response jar packages on the server, what kind of packaging released (maven? .CodePudding user response:
The building Lord finally how to solve the same problems