本文整理汇总了Java中com.sun.tools.javac.Main类的典型用法代码示例。如果您正苦于以下问题:Java Main类的具体用法?Java Main怎么用?Java Main使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Main类属于com.sun.tools.javac包,在下文中一共展示了Main类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pluginTest
import com.sun.tools.javac.Main; //导入依赖的package包/类
public void pluginTest() {
// List all java files from the plugin directory
File F = new File("plugin");
String[] inhalt = F.list();
for (int i = 0; i < inhalt.length; i++) {
if (inhalt[i].toLowerCase().endsWith(".java")) {
System.out.println(inhalt[i]);
}
}
// Compile the plugin and call a method
Main.compile(new String[] { "plugin/LpePlugin.java" });
try {
Plugin p = (Plugin) Class.forName("LpePlugin").newInstance();
System.out.println(p.getPlugInName());
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: doTest
import com.sun.tools.javac.Main; //导入依赖的package包/类
void doTest(File testJar, String... additionalArgs) {
List<String> options = new ArrayList<>();
options.add("-proc:only");
options.add("-processor");
options.add("T8076104");
options.add("-classpath");
options.add(System.getProperty("test.classes") + File.pathSeparator + testJar.getAbsolutePath());
options.addAll(Arrays.asList(additionalArgs));
options.add(System.getProperty("test.src") + File.separator + "T8076104.java");
int res = Main.compile(options.toArray(new String[0]));
if (res != 0) {
throw new AssertionError("Unexpected error code: " + res);
}
}
示例3: main
import com.sun.tools.javac.Main; //导入依赖的package包/类
public static void main(String[] args)
{
Debug.setDebugLevel(3);
File f = new File(MutationSystem.TESTSET_PATH);
String[] s = f.list(new ExtensionFilter("java"));
String[] pars = new String[2+s.length];
pars[0] = "-classpath";
pars[1] = MutationSystem.CLASS_PATH;
for (int i=0; i<s.length; i++)
{
pars[i+2] = MutationSystem.TESTSET_PATH + "/" + s[i];
}
try
{
// result = 0 : SUCCESS, result = 1 : FALSE
int result = Main.compile(pars,new PrintWriter(System.out));
if (result == 0)
{
Debug.println("Compile Finished");
}
} catch (Exception e)
{
e.printStackTrace();
}
}
示例4: test_existsWithResolvedDep
import com.sun.tools.javac.Main; //导入依赖的package包/类
/**
* Method that takes a valid (A program without any errors) file with Resolved dependencies and tests for the proper return code
*/
public void test_existsWithResolvedDep()
{
final StringWriter out = new StringWriter();
final StringWriter err = new StringWriter();
final String srcFile = RESOURCES + "Sample.java";
final File f = new File(srcFile);
final String testStr = f.getAbsolutePath();
final String option1 = "-classpath" ;
final String jarFile = RESOURCES + "Dependency.jar";
final File f1 = new File(jarFile);
final String option2 = f1.getAbsolutePath();
final int rc = Main.compile(new String[]{testStr, option1, option2}, new PrintWriter(out), new PrintWriter(err));
assertTrue("The program " + testStr + " should compile as dependency " + option2 + " is resolved", ! err.toString().contains("ERROR") && (rc == 0) );
}
示例5: run
import com.sun.tools.javac.Main; //导入依赖的package包/类
public static void run(String s, String[] imports) throws Exception {
File dataFolder = JavaShell.getInstance().getDataFolder();
File runtimeFolder = new File(dataFolder + File.separator + "runtime");
File javaFile = new File(runtimeFolder + File.separator + "run.java");
PrintWriter pw = new PrintWriter(javaFile);
pw.println("import org.bukkit.*;");
if (imports != null) {
for (String string : imports) pw.println("import " + string + ";");
}
pw.println("public class run {");
pw.print("public static void main(){" + s + "}}");
pw.close();
String[] args = new String[] {
"-cp", "." + File.pathSeparator + FileScanner.paths,
"-d", runtimeFolder.getAbsolutePath() + File.separator,
javaFile.getAbsolutePath()
};
int compileStatus = Main.compile(args);
if (compileStatus != 1) {
URL[] urls = new URL[] { runtimeFolder.toURI().toURL() };
URLClassLoader ucl = new URLClassLoader(urls);
Object o = ucl.loadClass("run").newInstance();
o.getClass().getMethod("main").invoke(o);
ucl.close();
} else {
throw new Exception("JavaShell compilation failure");
}
javaFile.delete();
File classFile = new File(runtimeFolder + File.separator + "run.class");
classFile.delete();
}
示例6: makeClass
import com.sun.tools.javac.Main; //导入依赖的package包/类
static String makeClass(String dir, String filename, String body) throws IOException {
File file = new File(dir, filename);
try (FileWriter fw = new FileWriter(file)) {
fw.write(body);
}
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
String args[] = { "-cp", dir, "-d", dir, "-XDrawDiagnostics", file.getPath() };
Main.compile(args, pw);
pw.close();
return sw.toString();
}
示例7: compile
import com.sun.tools.javac.Main; //导入依赖的package包/类
/**
* Compile java file by java file String.
*
* @param file
* @return
* @throws IOException
* @throws ClassNotFoundException
*/
public boolean compile(File file) {
logger.info("Preparing to compile java file.....");
File floder = new File(TARGETCLASSDIR);
if (!floder.exists())
floder.mkdirs();
logger.debug(TARGETCLASSDIR);
int result = Main.compile(new String[]{"-d", TARGETCLASSDIR,
TARGETCLASSDIR + FileSeparator
+ file.getName()});
return result == 0 ? true : false;
}
示例8: compile
import com.sun.tools.javac.Main; //导入依赖的package包/类
/**
* Compile java file by java file String.
*
* @param file
* @return
* @throws IOException
* @throws ClassNotFoundException
*/
public static boolean compile(File file)
{
logger.info("Preparing to compile java file.....");
int result = Main.compile(new String[]{"-d", CLASSDIR,
CLASSDIR.substring(USER_DIR.length() + 1) + File.separator
+ file.getName()});
return result == 0 ? true : false;
}
示例9: main
import com.sun.tools.javac.Main; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
File javaHomeDir = new File(System.getProperty("java.home"));
File outputDir = new File("outputDir" + new Random().nextInt(65536));
outputDir.mkdir();
outputDir.deleteOnExit();
File dnsjarfile = new File(javaHomeDir, "lib" + File.separator + "ext" + File.separator + "dnsns.jar");
File tmpJar = copyFileTo(dnsjarfile, outputDir);
String className = "TheJavaFile";
File javaFile = new File(outputDir, className + ".java");
javaFile.deleteOnExit();
FileOutputStream fos = new FileOutputStream(javaFile);
fos.write(generateJavaClass(className).getBytes());
fos.close();
int rc = Main.compile(new String[]{"-d", outputDir.getPath(),
"-classpath",
tmpJar.getPath(),
javaFile.getAbsolutePath()});
if (rc != 0) {
throw new Error("Couldn't compile the file (exit code=" + rc + ")");
}
if (tmpJar.delete()) {
System.out.println("jar file successfully deleted");
} else {
throw new Error("Error deleting file \"" + tmpJar.getPath() + "\"");
}
}
示例10: initCodeGenerator
import com.sun.tools.javac.Main; //导入依赖的package包/类
private AsmCodeGenerator initCodeGenerator(final String formFileName, final String className, final String testDataPath) throws Exception {
String tmpPath = FileUtil.getTempDirectory();
String formPath = testDataPath + formFileName;
String javaPath = testDataPath + className + ".java";
final int rc = Main.compile(new String[]{"-d", tmpPath, javaPath});
assertEquals(0, rc);
final String classPath = tmpPath + "/" + className + ".class";
final File classFile = new File(classPath);
assertTrue(classFile.exists());
final LwRootContainer rootContainer = loadFormData(formPath);
final AsmCodeGenerator codeGenerator = new AsmCodeGenerator(rootContainer, myClassFinder, myNestedFormLoader, false, new ClassWriter(ClassWriter.COMPUTE_FRAMES));
final FileInputStream classStream = new FileInputStream(classFile);
try {
codeGenerator.patchClass(classStream);
}
finally {
classStream.close();
FileUtil.delete(classFile);
final File[] inners = new File(tmpPath).listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith(className + "$") && name.endsWith(".class");
}
});
if (inners != null) {
for (File file : inners) FileUtil.delete(file);
}
}
return codeGenerator;
}
示例11: execute
import com.sun.tools.javac.Main; //导入依赖的package包/类
public WorkResult execute(JavaCompileSpec spec) {
LOGGER.info("Compiling with Sun Java compiler API.");
String[] options = createCommandLineOptions(spec);
int exitCode = Main.compile(options);
if (exitCode != 0) {
throw new CompilationFailedException();
}
return new SimpleWorkResult(true);
}
示例12: main
import com.sun.tools.javac.Main; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
File javaHomeDir = new File(System.getProperty("java.home"));
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
File outputDir = new File(tmpDir, "outputDir" + new Random().nextInt(65536));
outputDir.mkdir();
outputDir.deleteOnExit();
File dnsjarfile = new File(javaHomeDir, "lib" + File.separator + "ext" + File.separator + "dnsns.jar");
File tmpJar = copyFileTo(dnsjarfile, outputDir);
String className = "TheJavaFile";
File javaFile = new File(outputDir, className + ".java");
javaFile.deleteOnExit();
FileOutputStream fos = new FileOutputStream(javaFile);
fos.write(generateJavaClass(className).getBytes());
fos.close();
int rc = Main.compile(new String[]{"-d", outputDir.getPath(),
"-classpath",
tmpJar.getPath(),
javaFile.getAbsolutePath()});
if (rc != 0) {
throw new Error("Couldn't compile the file (exit code=" + rc + ")");
}
if (tmpJar.delete()) {
System.out.println("jar file successfully deleted");
} else {
throw new Error("Error deleting file \"" + tmpJar.getPath() + "\"");
}
}
示例13: test_nonExists
import com.sun.tools.javac.Main; //导入依赖的package包/类
/**
* Method that takes in a non-existent file and checks the output for the appropriate Error message
*
*/
public void test_nonExists() {
final StringWriter out = new StringWriter();
final String testStr = "no_this_test.java";
final int rc = Main.compile(new String[]{testStr}, new PrintWriter(out));
assertTrue("The output should have " + testStr, out.toString().contains("missing") && rc == 1);
}
示例14: test_exists
import com.sun.tools.javac.Main; //导入依赖的package包/类
/**
* Method that takes a valid (A pgm without any errors) file and tests for the proper return code
*/
public void test_exists()
{
final StringWriter out = new StringWriter();
final StringWriter err = new StringWriter();
final String srcFile = RESOURCES + "Simple.java";
final File f = new File(srcFile);
final String testStr = f.getAbsolutePath();
final int rc = Main.compile(new String[]{testStr}, new PrintWriter(out), new PrintWriter(err));
assertTrue("The program " + testStr + " should cleanly compile", err.toString().trim().equals("") && rc == 0 );
}
示例15: test_existsWithUnresolvedDep
import com.sun.tools.javac.Main; //导入依赖的package包/类
/**
* Method that takes a valid (A program without any errors) file but with unresolved dependencies and tests for the proper return code
*/
public void test_existsWithUnresolvedDep()
{
final StringWriter out = new StringWriter();
final StringWriter err = new StringWriter();
final String srcFile = RESOURCES + "Sample.java";
final File f = new File(srcFile);
final String testStr = f.getAbsolutePath();
final int rc = Main.compile(new String[]{testStr}, new PrintWriter(out), new PrintWriter(err));
assertTrue("The program " + testStr + " shouldn't compile due to unresolved dependencies", err.toString().contains("ERROR") && (rc == 1) );
}