运行时的Java编译器 [英] Java compiler at Runtime

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

问题描述

在我当前的项目中,我需要在运行时编译Java代码(在后台处理来自用户的输入).这与classpath中的tools.jar一起正常工作.但是,并非我的程序的所有用户都在其系统上安装了JDK.其中一些仅具有JRE,在这种情况下,运行时没有Java编译器可用.我可以通过将Sun的tools.jar作为工具的一部分来解决该问题.

In my current project, I need to compile java code at runtime (in the background to process input from the user). This works fine with tools.jar in the classpath. However, not all users of my program have JDK installed on their system. Some of them only have JRE and in that case there is no java compiler available at runtime. I can solve that problem by including tools.jar from Sun as a part of my tool.

但是tools.jar很大(> 12 MB). 问题是,尽管我只对这个jar提供的功能的一小部分感兴趣,但我必须包括大的jar文件.

But tools.jar is very big (>12 MB). The problem is that I have to include the large jar file, although I am interested only in a small fraction of the functionality provided by this jar.

  1. 是否可以分解 tools.jar文件,以便我有一个 一小类的子集 编译Java代码所需 只要?

  1. Is it possible to break up the tools.jar file so that I have a small subset of classes that are required for compiling java code only?

这是非法的吗?

非常感谢.

推荐答案

eclise编译器只有1.6 MB,并且可以正常运行.您可以

The eclise compiler is only 1.6 MB and should work without eclipse. You can download it here. Also it looks like it implements the JavaCompiler api.

它是在Eclipse公共许可证下获得许可的,因此将其包含在您自己的应用程序中应该没问题.

It is licensed under the eclipse public licence so including it in your own aplication should be no problem.

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

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