Package javax.tools.JavaCompiler

Examples of javax.tools.JavaCompiler.CompilationTask.call()


        //编译选项,在编译java文件时,编译程序会自动的去寻找java文件引用的其他的java源文件或者class。 -classpath选项就是定义class文件的查找目录。 
        Iterable<String> options = Arrays.asList("-encoding",encoding,"-classpath",jars,"-d", distDir);  
        CompilationTask compilationTask = compiler.getTask(null, fileManager, diagnostics, options, null, compilationUnits);  

        // 运行编译任务  
        boolean res= compilationTask.call();
        try {
      fileManager.close();
    } catch (IOException e) {
      log.error("关闭文件管理器失败");
      log.error(e.getMessage());
View Full Code Here


        ByteArrayFileManager bafm = new ByteArrayFileManager(
            compiler.getStandardFileManager(null, null, null), targetClass);
        StringWriter sw = new StringWriter();
        CompilationTask task = compiler.getTask(sw, bafm, diagnosticsCollector, OPTIONS, null,
            compilationUnits);
        task.call();
        return targetClass.toByteArray();
    }

    // wrapper class - not really a 'FileObject', uses in-memory string 'source'
    class JavaSourceFromString extends SimpleJavaFileObject {
View Full Code Here

        ByteArrayFileManager bafm = new ByteArrayFileManager(
            compiler.getStandardFileManager(null, null, null), targetClass);
        StringWriter sw = new StringWriter();
        CompilationTask task = compiler.getTask(sw, bafm, diagnosticsCollector, OPTIONS, null,
            compilationUnits);
        task.call();
        return targetClass.toByteArray();
    }

    // wrapper class - not really a 'FileObject', uses in-memory string 'source'
    class JavaSourceFromString extends SimpleJavaFileObject {
View Full Code Here

   
    CompilationTask cTask = compiler.getTask(null, fileManager, null, null,
        null,
        fileManager.getJavaFileObjects(
            javaFiles.toArray(new File[javaFiles.size()])));
    assertTrue(cTask.call());
  }
}
View Full Code Here

   
    CompilationTask cTask = compiler.getTask(null, fileManager, null, null,
        null,
        fileManager.getJavaFileObjects(
            javaFiles.toArray(new File[javaFiles.size()])));
    assertTrue(cTask.call());
  }
}
View Full Code Here

    List<String> options = new ArrayList<String>();
    options.add(includeDebugInfo ? "-g" : "-g:none");
    options.addAll(COMMON_ARGS);
    CompilationTask task = compiler.getTask(null, staticFileManager, null, options, null, compilationUnits);
    Boolean result = task.call();
    fileManager.close();
    if (Boolean.TRUE.equals(result)) {
      return staticFileManager.outputFiles();
    }
    return Collections.emptyList();
View Full Code Here

    List<JavaFileObject> jFiles = new ArrayList<JavaFileObject>(1);
    jFiles.add(new CharSequenceJavaFileObject(fullName, code));

    CompilationTask compilerTask = compiler.getTask(null, fileManager, null, null, null, jFiles);
    return Boolean.TRUE.equals(compilerTask.call());
  }

  private ClassLoader getClassLoader() {
    return fileManager.getClassLoader(null);
  }
View Full Code Here

   
    CompilationTask cTask = compiler.getTask(null, fileManager, null, null,
        null,
        fileManager.getJavaFileObjects(
            javaFiles.toArray(new File[javaFiles.size()])));
    assertTrue(cTask.call());
  }
}
View Full Code Here

      DrillJavaFileObject compilationUnit = new DrillJavaFileObject(className.dot, sourceCode);

      CompilationTask task = compiler.getTask(null, fileManager, listener, compilerOptions, null, Collections.singleton(compilationUnit));

      // Run the compiler.
      if(!task.call()) {
        throw new CompileException("Compilation failed", null);
      } else if (!compilationUnit.isCompiled()) {
        throw new ClassNotFoundException(className + ": Class file not created by compilation.");
      }
      // all good
View Full Code Here

    String[] options = new String[] { "-d", "target/classes" };
    List<String> compileOptions = Arrays.asList(options);

    CompilationTask task = compiler.getTask(null, fileManager, diagnosticListener, compileOptions, null,
        compilationUnits);
    Boolean result = task.call();
    /*
    List<Diagnostic<? extends JavaFileObject>> diagnostics = diagnosticListener.getDiagnostics();
    for (Diagnostic<? extends JavaFileObject> diagnosticItem : diagnostics) {
      System.out.format("Error in %s", diagnosticItem);
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.