[英]Compiled Java compiler in JAR form?
I have an application which requires compiling a .java file into a .class file within the application . 我有一个应用程序,需要将.java文件编译为应用程序内的 .class文件。 Ideally, I'd like to have a JAR that I could use its api to compile by giving two arguments: the name of the file to be compiled and the directory to store the .class file.
理想情况下,我想拥有一个JAR,可以通过提供两个参数来使用其JAR的api:要编译的文件的名称和用于存储.class文件的目录。 My application will use the Java compiler, which will be packaged and shipped with the software.
我的应用程序将使用Java编译器,该软件包将打包并随软件一起提供。
I actually have a small java compiler like I describe in JAR form, but it only has a subset of what java 7.0 has. 我实际上有一个小的Java编译器(如我以JAR形式描述的那样),但是它仅包含Java 7.0的一部分。
Is the java compiler available in Jar form like this? Java编译器是否可以像这样的Jar形式使用?
the compiler is in tools.jar. 编译器位于tools.jar中。
refer to http://docs.oracle.com/javase/6/docs/api/javax/tools/package-summary.html 请参阅http://docs.oracle.com/javase/6/docs/api/javax/tools/package-summary.html
Java Compiler API (JSR 199) was created for this purpose, you create a compiler instance like this: 为此目的创建了Java Compiler API(JSR 199) ,您可以像下面这样创建一个编译器实例:
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
Here is a good educational tutorial on Generating Java classes dynamically 这是有关动态生成Java类的很好的教学教程
and here is a related question with example code 这是一个带有示例代码的相关问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.