如何解决JDK14 javacompiler:无法将编译java文件加载到maven读取类文件的类路径中
Log.LogInfo("Compile Start..........");
String source = getMethodString(newClassName);//package testcase.cases public class Admin(){@Test public void test_case(){}}
Path currentRelativePath = Paths.get("");
String projectDirectory = currentRelativePath.toAbsolutePath().toString();
File root = new File(projectDirectory); // On Windows running on C:\,this is C:\java.
File sourceFile = new File(root,"test/"+newClassName+".java");
sourceFile.getParentFile().mkdirs();
Files.write(sourceFile.toPath(),source.getBytes(StandardCharsets.UTF_8));
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null,null,null);
Iterable sourcefiles = fileManager.getJavaFileObjects(sourceFile);
List<String> optionList = new ArrayList<String>();
// set compiler's classpath to be same as the runtime's
optionList.addAll(Arrays.asList("-d","target/classes"));
boolean result = compiler.getTask(null,fileManager,optionList,sourcefiles).call();
这是我的代码,用于将java文件编译并将类加载到目标/类中,但是在eclipse上可以正常工作,但是当构建项目并制作具有maven依赖项的jar并在命令行上执行jar(通过开发人员机器上的批处理文件)时,它会创建新代码文件夹目标/类导致在任何情况下都不会执行。
这是我的内部Suite文件
<packages><package name="testcase.*" /></packages>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。