gpt4 book ai didi

Java : Expose only a single package in a jar file

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:16:40 25 4
gpt4 key购买 nike

我想要一个只有 API 包可以访问的 jar 文件。所有其他包(包含实现)将无法被另一个 jar(或任何其他类)访问。

这可能吗?

如果是,怎么办?

最佳答案

当前计划用于 Java 8(2012 年?)的是 JSR 294 .此 JSR 将更好的模块化语言结构引入 Java。

Today, an implementation can be partitioned into multiple packages. Subparts of such an implementation need to be more tightly coupled to each other than to the surrounding software environment. Today designers are forced to declare elements of the program that are needed by other subparts of the implementation as public - thereby making them globally accessible, which is clearly suboptimal.

Alternately, the entire implementation can be placed in a single package. This resolves the issue above, but is unwieldy, and exposes all internals of all subparts to each other.

The language changes envisioned will resolve these issues. In particular, we expect to introduce a new notion of modules (superpackages) at the language level where existing public access control would apply only within a language level module and access to API's from outside a module would be restricted to API's the module explicitly exports.

现在我相信专家组仍在讨论这个概念的细节。但我相信您可以做的一件事是(来源:Super Packages in Java 7.0):

superpackage com.myorg.myApp.model
{
member package com.myorg.myApp.model.swing;

member package com.myorg.myApp.model.html;

export com.myorg.myApp.model.swing.SEmployee;
export com.myorg.myApp.model.swing.SDepartment;

export package com.myorg.myApp.model.html;
}

换句话说,对于给定的“ super 包”,您可以定义导出和不导出的内容,独立于 public 等可见性关键字。

关于Java : Expose only a single package in a jar file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4388715/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com