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

查看:26
本文介绍了用 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天全站免登陆