javax.tools是否依赖JDK? [英] Does javax.tools depend on the JDK?

查看:236
本文介绍了javax.tools是否依赖JDK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用JavaCompiler动态创建一些类.

I want to use JavaCompiler to dynamically create some classes.

我找到了javax.tools包的源代码,但是没有实现;互联网上的一些帖子说这取决于tools.jar,我不确定tools.jar是否与JRE相关.

I found the source code of the javax.tools package, but there is no implementation; some posts on the internet say it depends on tools.jar, I am not sure tools.jar associates with JRE.

那么,我可以在未安装JDK的JRE环境中运行该程序吗?

So, can I run the program in a JRE environment without JDK installed?

另一个问题,JavaCompiler的实现细节是什么,是否正在创建一个新的过程来调用javac命令?

Another question, what is the implementation detail of JavaCompiler, is it creating a new process to invoke the javac command?

谢谢

推荐答案

JRE需要在该包中包括接口和类,但不需要提供实现.

JRE's need to include the interfaces, and classes in that package, but do not need to provide implementations.

Sun的JRE不会,并且通过调用 ToolProvider.getSystemJavaCompiler() .

Sun's JRE doesn't, and returns null from calling ToolProvider.getSystemJavaCompiler().

另一个问题是针对Java 5的.

This other question addresses java 5.

这是

Here's a blog post by Morten Nobel-Jørgensen on how to use eclipse's compiler as an implementation of javax.tools.JavaCompiler.

JavaCompiler javac = new EclipseCompiler();

这篇关于javax.tools是否依赖JDK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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