简体   繁体   中英

How to EMBED external jar and FOLDERS into one executable jar file using NetBeans IDE

I have a netbean project with standard folder structure. Project Dependencies are guava.jar, a folder with plain text file, and a folder with nested folders, each having images, totaling to over 20K images and a size of 500MB. Standard build process yields myjar.jar which works perfectly outside the ide if it is run in the same folders as my dependencies. Folder tree is something like

root/
  image/
     folder1/
             image1.png
             image2.png
       folder2/
      ...
      ...
   txtfolder/
      file.txt
   lib/
      guava.jar
   myJar.jar

Deploying above file structure works perfectly, but the requirement is to deploy the above file structure as ONE executable jar file, say myJarAll.jar (naturally, with a size of nearly 600MB).

I have already tried adding jar files and folders to netbean project as dependencies and then doing a clean build but it doesn't generate a myJarAll.jar. Ideal situation would be to have zero changes to the source code and heck up the ant file to make it generate a combined jar.

One solution that I have experimented with is to create external jar files from images and text folders and add them up as dependencies to a project. Problem with this approach is that it expects considerable changes to the original source code.

Any help, suggestion or tools that can solve this problem.

Thanks

Easiest would be to have a myJar.jar with a META-INF/MANIFEST.MF listing the library jars in lib . In the lib folder besides guava.jar you can create a myResources.jar stemming from a second project. Or add those files to myJar.jar. (The NetBeans IDE already maintains the manifest.)

Unavoidable is loading the files as read-only java resources on the class path, under the src directory (see the Files tab in NetBeans). So the question is whether you are already using getClass().getResourceAsStream("/txtfolder/file.txt") .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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