Documentation

The Java™ Tutorials

Trail: The Extension MechanismTrail:扩展机制

The extension mechanism provides a standard, scalable way to make custom APIs available to all applications running on the Java platform. 扩展机制提供了一种标准的、可伸缩的方式,使自定义API可用于Java平台上运行的所有应用程序。Java extensions are also referred to as optional packages. Java扩展也被称为可选包This trail may use both terms interchangeably.这两个术语可以互换使用。

Extensions are groups of packages and classes that augment the Java platform through the extension mechanism. 扩展是通过扩展机制扩充Java平台的一组包和类。The extension mechanism enables the runtime environment to find and load extension classes without the extension classes having to be named on the class path. 扩展机制使运行时环境能够查找和加载扩展类,而不必在类路径上命名扩展类。In that respect, extension classes are similar to the Java platform's core classes. 在这方面,扩展类类似于Java平台的核心类。That's also where extensions get their name -- they, in effect, extend the platform's core API.这也是扩展的由来——实际上,它们扩展了平台的核心API。

Since this mechanism extends the platform's core API, its use should be judiciously applied. 因为这种机制扩展了平台的核心API,所以应该明智地应用它。Most commonly it is used for well standardized interfaces such as those defined by the Java Community Process, although it may also be appropriate for site wide interfaces.它通常用于标准化良好的接口,如Java社区流程定义的接口,尽管它也适用于站点范围的接口。

This figure shows the relationships between Application, Java Platform, and Extensions.

As the diagram indicates, extensions act as "add-on" modules to the Java platform. Their classes and public APIs are automatically available to any applications running on the platform.如图所示,扩展充当Java平台的“附加”模块。它们的类和公共API自动可用于平台上运行的任何应用程序。

The extension mechanism also provides a means for extension classes to be downloaded from remote locations for use by applets.还提供了从远程位置下载小程序的扩展机制。

Extensions are bundled as Java Archive (JAR) files, and this trail assumes that you are familiar with the JAR file format. 扩展被绑定为Java归档(JAR)文件,本教程假设您熟悉JAR文件格式。If you're not up to speed on JAR files, you might want to review some JAR-file documentation before proceeding with the lessons in this trail:如果您对JAR文件的学习速度不快,在继续本教程中的课程之前,您可能希望查看一些JAR文件文档:

This trail has two lessons:这条线索有两个教训:

Creating and Using Extensions创建和使用扩展

This section shows you what you need to do to add an extension to your Java platform and how applets can benefit from the extension mechanism by downloading remote extension classes.本节向您展示了向Java平台添加扩展需要做什么,以及小程序如何通过下载远程扩展类从扩展机制中获益。

Making Extensions Secure使扩展安全

This section describes security privileges and permissions that are granted to extensions on your platform. 本节介绍授予平台上扩展的安全特权和权限。You'll see how to use the Java platform's security architecture if you're writing extensions classes of your own.如果您正在编写自己的扩展类,您将看到如何使用Java平台的安全体系结构。

Additional Documentation附加文件

You can find further information about extensions in the The Java Extensions Mechanism section of the JDK documentation.您可以在JDK文档的Java扩展机制部分找到关于扩展的更多信息。


Previous page: Beginning of Tutorial
Next page: Creating and Using Extensions