当前位置: 首页>>代码示例>>Java>>正文


Java Main类代码示例

本文整理汇总了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();
    }
}
 
开发者ID:nilsschmidt1337,项目名称:ldparteditor,代码行数:21,代码来源:plugin_loading.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:T8076104.java

示例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();
   }
}
 
开发者ID:jeffoffutt,项目名称:muJava,代码行数:27,代码来源:compileTestcase.java

示例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) );
}
 
开发者ID:shannah,项目名称:cn1,代码行数:22,代码来源:MainTest.java

示例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();
}
 
开发者ID:Ladinn,项目名称:JavaShell,代码行数:40,代码来源:Runner.java

示例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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:BadClass.java

示例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;
}
 
开发者ID:ShawnShoper,项目名称:x-job,代码行数:20,代码来源:ClassLoaderHandler.java

示例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;
}
 
开发者ID:ShawnShoper,项目名称:x-job,代码行数:17,代码来源:JDKCompile.java

示例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() + "\"");
    }
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:30,代码来源:T6558476.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:AsmCodeGeneratorTest.java

示例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);
}
 
开发者ID:Pushjet,项目名称:Pushjet-Android,代码行数:12,代码来源:SunJavaCompiler.java

示例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() + "\"");
    }
}
 
开发者ID:aducode,项目名称:openjdk-source-code-learn,代码行数:31,代码来源:T6558476.java

示例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);
  }
 
开发者ID:shannah,项目名称:cn1,代码行数:11,代码来源:MainTest.java

示例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 );
}
 
开发者ID:shannah,项目名称:cn1,代码行数:16,代码来源:MainTest.java

示例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) );
}
 
开发者ID:shannah,项目名称:cn1,代码行数:16,代码来源:MainTest.java


注:本文中的com.sun.tools.javac.Main类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。