blob: f36454e028e46d9538c11711ba0fbb4ac6eef916 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
/*
* SunLibCompiler.java
*
* Apr 16, 1999 Michiaki Tatsubori
*/
package jp.ac.tsukuba.openjava;
import java.io.OutputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import io.devnulllabs.openjava.ojc.JavaCompiler;
/**
* The class <code>SunLibCompiler</code> is an adapter for the compiler
* which invokes Sun's library javac.
* <p>
* The class path must includes lib/tools.jar in the jdk package.
*
* @since jdk1.2
*/
public class SunLibCompiler implements JavaCompiler {
Object sunJavac;
//sun.tools.javac.Main m;
Method compileMethod;
public SunLibCompiler() {
//m = new sun.tools.javac.Main(System.err, "javac");
try {
Class clazz = Class.forName("sun.tools.javac.Main");
Constructor cons =
clazz.getConstructor(
new Class[] { OutputStream.class, String.class });
sunJavac = cons.newInstance(new Object[] { System.err, "javac" });
compileMethod =
clazz.getMethod("compile", new Class[] { String[].class });
} catch (Exception ex) {
throw new RuntimeException(ex.toString());
}
}
public static void main(String[] args) {
new SunLibCompiler().compile(args);
}
public void compile(String[] args) {
//sun.tools.javac.Main.main( args );
//m.compile(args);
try {
compileMethod.invoke(sunJavac, new Object[] { args });
} catch (Exception ex) {
throw new RuntimeException(ex.toString());
}
}
}
|