Search code examples
javaeclipsejarlibrariesdirectory-structure

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.

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 !


Solution

  • No, the JAR file specification dictates a specific structure. 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. That's why build tools (gradle, maven, ant, etc) exist to help produce the JAR specification structure exactly.

    Realize that in your example, org and com are not really folders, they're they're nodes (levels) in package structures. Same for your main - it's just a package.

    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.

    META-INF and the manifest file are dictated by the spec and can't be changed or relocated.