使用Java程序编译Java文件 [英] Compile a Java file... with a Java program

查看:173
本文介绍了使用Java程序编译Java文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用Java编写的程序是否有可能使用JDK编译器编译文件(除了使用Java打开命令提示符并在其上抛出javac命令来编译文件)?

解决方案

在Java 6及更高版本中,有一个API可以使用编译器。这可能就是你要找的。

http://www.javabeat.net/2007/04/the-java-6-0-compiler-api/



http://docs.oracle.com/javase/6/docs/ api / javax / tools / JavaCompiler.html



请注意,您需要JDK来使编译器可用。 JRE是不够的。如果这是一个问题,请考虑在您的应用程序中嵌入Eclipse Java编译器。


Is it possible for a program written in Java to compile a file using the JDK compiler (aside from using Java to open command prompt and throw the "javac" command at it to compile the file)?

解决方案

In Java 6 and onwards there is an API to use the compiler. This might be what you are looking for.

http://www.javabeat.net/2007/04/the-java-6-0-compiler-api/

http://docs.oracle.com/javase/6/docs/api/javax/tools/JavaCompiler.html

Note that you need a JDK to have the compiler available. JRE will not be enough. If that is a problem consider embedding the Eclipse Java compiler in your application.

这篇关于使用Java程序编译Java文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆