繁体   English   中英

从存档(jar)中的文件导入

[英]Import from file inside an archive (jar)

我有一个用 Java + JavaScript 编写的应用程序。 用户可以使用 JavaScript 为这个应用程序编写插件,方法是将他们的文件放在 Jar 文件旁边的plugins文件夹中。 Some scripts might need access to internal JavaScript classes (eg the plugin should default export a class that extends the JavaScript Plugin class) but these classes are defined in JavaScript files that reside inside the Jar and are therefor inaccessible from outside the Jar since you can' t import Plugin from "../MyApp.jar/scripts/Plugin.js"

我唯一的理论解决方案是将 Jar 内部的所有脚本文件复制到 Jar 外部的文件夹scripts/中,但这是否可行? Jar 内部和 Jar 外部的Plugin class 不会是不同Plugin类吗? 或者 JavaScript 是否足够动态,只要两个Plugin类 100% 相同就没有关系?

JavaScript 有一个全局命名空间。 部分代码是从您的源存档中加载的,还是从外部文件中加载的,都没有关系。 You may be worried because in Java each class loader gets a namespace of its own, and things get confusing when a class is loaded by different class loader (the two copies look the same but are incompatible).

JavaScript没有这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM