简体   繁体   English

在可执行的.JAR中组织库和资源

[英]Organize libraries and resources in an executable .JAR

I want to re-organize all files in my executable .JAR (resources, external librairies, and application .class files) using Eclipse. 我想使用Eclipse重新组织可执行文件.JAR中的所有文件(资源,外部库和应用程序.class文件)。

What I have : 我有的 :

My.JAR

> folder "com" for external library 1 (com.apple.***)

> folder "org" for external library 2 (org.javasypt.***)

> folder "main" (package)
    >> .class files

> folder "resources"
    >> all resources files (images, texts...)

> folder "META-INF"
    >> "MANIFEST.MF" file

What I want to have : 我要拥有的东西:

My.JAR

> folder "main" 
    >> folder "resources"
        >>> all resources files

    >> folder "libraries"
        >>> external library 1 (com.apple.***)
        >>> external library 2 (org.javasypt.***)

    >> .class files

> folder "META-INF"
    >> "MANIFEST.MF" file

Is it possible to obtain this ? 有可能获得这个吗? Thanks ! 谢谢 !

No, the JAR file specification dictates a specific structure. 不, JAR文件规范规定了特定的结构。 You're trying to mix organization-for-humans and organization for the runtime, but those two concepts are distinct. 您正在尝试将人为组织和运行时组织混合在一起,但是这两个概念是不同的。 By all means, organize your source as you see fit, but you can't expect the runtime (JVM) to understand any arbitrary structure. 一定要按自己的意愿组织源代码,但是不能期望运行时(JVM)理解任何任意结构。 That's why build tools (gradle, maven, ant, etc) exist to help produce the JAR specification structure exactly. 这就是为什么存在构建工具(gradle,maven,ant等)来帮助准确生成JAR规范结构的原因。

Realize that in your example, org and com are not really folders, they're they're nodes (levels) in package structures. 意识到在您的示例中, orgcom并不是真正的文件夹,它们是包结构中的节点(级别)。 Same for your main - it's just a package. main -只是一个包裹。

resources is the only thing that you have some flexibility, as you can name that whatever you want as long as the code that is reading content from it knows that name to expect. resources是您唯一具有灵活性的东西,因为只要您要读取的内容的代码都知道要使用的名称,就可以随便命名。

META-INF and the manifest file are dictated by the spec and can't be changed or relocated. META-INF和清单文件由规范规定,不能更改或重定位。

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

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