簡體   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