Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import info.kgeorgiy.java.advanced.implementor.BaseImplementorTest;
- private void compileClass(Path fileName, Path root) throws ImplerException {
- JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
- if (javaCompiler == null) {
- throw new ImplerException("Java compiler not found");
- }
- final List<String> args = new ArrayList<>();
- args.add(fileName.toString());
- args.add("-cp");
- args.add(root + File.pathSeparator + getClassPath());
- int returnCode = javaCompiler.run(null, null, null, args.toArray(String[]::new));
- if (returnCode != 0) {
- throw new ImplerException("Compilation failed");
- }
- }
- private static String getClassPath() {
- try {
- return Path.of(BaseImplementorTest.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toString();
- } catch (final URISyntaxException e) {
- throw new AssertionError(e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement