本文整理汇总了Java中com.sun.tools.javac.Main类的典型用法代码示例。如果您正苦于以下问题:Java Main类的具体用法?Java Main怎么用?Java Main使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Main类属于com.sun.tools.javac包,在下文中一共展示了Main类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: compile
import com.sun.tools.javac.Main; //导入依赖的package包/类
public int compile(String[] opts, String[] sourceDirs) throws GeneratorException {
if (log.isDebugEnabled()) log.debug("compile(opts=" + Arrays.toString(opts) + ", sourceDirs=" + Arrays.toString(sourceDirs));
System.out.println("Compile Java source, opts=" + Arrays.toString(opts) + ", sourceDirs=" + Arrays.toString(sourceDirs));
List<File> files = findSourceFiles(sourceDirs);
if (log.isDebugEnabled()) log.debug("files=" + files);
List<String> params = new ArrayList<String>();
for (String opt : opts) params.add(opt);
for (File file : files) params.add(file.getAbsolutePath());
StringWriter sw = new StringWriter();
PrintWriter pr = new PrintWriter(sw);
int status = Main.compile(params.toArray(new String[0]), pr);
String msg = sw.toString();
if (status != 0) {
ErrorInfo errInfo = new ErrorInfo();
errInfo.msg = "Compile failed. " + msg;
throw new GeneratorException(errInfo);
}
else {
log.info("Sources successfully compiled.");
if (msg.length() != 0) log.info(msg);
}
if (log.isDebugEnabled()) log.debug(")compile=" + status);
return status;
}
开发者ID:wolfgangimig,项目名称:byps,代码行数:33,代码来源:CompileSource.java
示例17: compile
import com.sun.tools.javac.Main; //导入依赖的package包/类
public static int compile(String[] args) {
return Main.compile(args);
}
开发者ID:tranleduy2000,项目名称:javaide,代码行数:4,代码来源:Javac.java
示例18: main
import com.sun.tools.javac.Main; //导入依赖的package包/类
public static void main(String[] zArgs) {
int compile = Main.compile(zArgs);
}
开发者ID:tranleduy2000,项目名称:javaide,代码行数:4,代码来源:javac.java
示例19: testTooSoon
import com.sun.tools.javac.Main; //导入依赖的package包/类
@Test
public void testTooSoon(Path base) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src,
"package test; public class Test {}");
Path out = base.resolve("out");
Files.createDirectories(out);
Path reg = base.resolve("reg");
Path regFile = reg.resolve("META-INF").resolve("services").resolve(Plugin.class.getName());
Files.createDirectories(regFile.getParent());
try (OutputStream regOut = Files.newOutputStream(regFile)) {
regOut.write(PluginImpl.class.getName().getBytes());
}
String processorPath = System.getProperty("test.class.path") + File.pathSeparator + reg.toString();
JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
Path testSource = src.resolve("test").resolve("Test.java");
try (StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
com.sun.source.util.JavacTask task =
(com.sun.source.util.JavacTask) javaCompiler.getTask(null,
null,
d -> { throw new IllegalStateException(d.toString()); },
Arrays.asList("--processor-path", processorPath,
"-processor", AP.class.getName(),
"-Xplugin:test"),
null,
fm.getJavaFileObjects(testSource));
task.call();
}
Main.compile(new String[] {"--processor-path", processorPath,
"-Xplugin:test",
testSource.toString()});
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:42,代码来源:QueryBeforeEnter.java
示例20: run
import com.sun.tools.javac.Main; //导入依赖的package包/类
void run() throws IOException {
String testClasses = System.getProperty("test.classes");
File pluginRegistration =
new File(testClasses + "/META-INF/services/com.sun.source.util.Plugin");
pluginRegistration.getParentFile().mkdirs();
try (Writer metaInfRegistration = new FileWriter(pluginRegistration)) {
metaInfRegistration.write("CompileEvent$PluginImpl");
}
File test = new File(testClasses + "/Test.java");
test.getParentFile().mkdirs();
try (Writer testFileWriter = new FileWriter(test)) {
testFileWriter.write("public class Test { }");
}
StringWriter out;
//test events fired to listeners registered from plugins
//when starting compiler using Main.compile
out = new StringWriter();
int mainResult = Main.compile(new String[] {
"-XDaccessInternalAPI", "-Xplugin:compile-event", "-processorpath", testClasses, test.getAbsolutePath()
}, new PrintWriter(out, true));
if (mainResult != 0)
throw new AssertionError("Compilation failed unexpectedly, exit code: " + mainResult);
assertOutput(out.toString());
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
try (StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null)) {
Iterable<? extends JavaFileObject> testFileObjects = fm.getJavaFileObjects(test);
//test events fired to listeners registered from plugins
//when starting compiler using JavaCompiler.getTask(...).call
List<String> options =
Arrays.asList("-XDaccessInternalAPI", "-Xplugin:compile-event", "-processorpath", testClasses);
out = new StringWriter();
boolean compResult = comp.getTask(out, null, null, options, null, testFileObjects).call();
if (!compResult)
throw new AssertionError("Compilation failed unexpectedly.");
assertOutput(out.toString());
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:42,代码来源:CompileEvent.java
注:本文中的com.sun.tools.javac.Main类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论