Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of dynamic compilation of JDK6

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the relevant knowledge of "what is the method of dynamic compilation of JDK6". The editor shows you the operation process through an actual case. The method of operation is simple, fast and practical. I hope this article "what is the method of dynamic compilation of JDK6" can help you solve the problem.

JDK6 began to provide dynamically compiled API, which can be used in many application scenarios, such as dynamic loading (modification) services, high-performance dynamic business logic implementation (using script or template engine to achieve efficiency can not meet the requirements), and so on.

The corresponding interfaces of API are all under the javax.tools package, and common compilation methods are based on text files, memory strings, etc., in fact, URI-based byte streams can be used, that is, remote Java source code can also be used. There are many examples of dynamic compilation in the form of existing files. Here I introduce dynamic compilation in the form of strings in memory.

The simple code flow is as follows:

Java code

/ / obtain the dynamic compiler JavaCompiler compiler = ToolProvider.getSystemJavaCompiler () through the system tool provider; / / obtain a file manager whose main function is to provide rules for all file operations, / / such as source code path, target directory of compiled classpath,class files, etc., whose related attributes provide the default value StandardJavaFileManager fileManager = compiler.getStandardFileManager (null, null, null) / / get CompilationTask and call / / get the CompilationTask method prototype: getTask (Writer out, JavaFileManager fileManager, DiagnosticListener)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report