Silviu Draghici
Silviu Draghici

Reputation: 328

Adding folders to jars

I created a folder called "res" in which I put all the sound files and picture files that my application uses. I added the folder to my project as a library so using

"/filename.whatever"

as the filepath works when I run the project in netbeans. However, when I try to clean and build it says:

Not copying library path\res , it's a directory.

How do I get netbeans to put the folder in the jar so that it still works with the same filepath?

Upvotes: 1

Views: 219

Answers (1)

iCrazybest
iCrazybest

Reputation: 3115

This is the answer of the SAM

This was a pain, using netBeans IDE 7.2.

  1. You need to remember that Netbeans cleans up the Build folder whenever you rebuild, so
  2. Add a resource folder to the src folder:

    • (project)
      • src
        • project package folder (contains .java files)
        • resources (whatever name you want)
        • images (optional subfolders)
  3. After the clean/build this structure is propogated into the Build folder:

    • (project)
      • build
        • classes
          • project package folder (contains generated .class files)
          • resources (your resources)
          • images (your optional subfolders)

To access the resources:

dlabel = new JLabel(new ImageIcon(getClass().getClassLoader().getResource("**resources/images/logo.png**")));

and:

if (common.readFile(getClass().getResourceAsStream **("/resources/allwise.ini**"), buf).equals("OK")) {

worked for me. Note that in one case there is a leading "/" and in the other there isn't. So the root of the path to the resources is the "classes" folder within the build folder.

Double click on the executable jar file in the dist folder. The path to the resources still works.

Src : How to correctly get image from 'Resources' folder in NetBeans

Upvotes: 2

Related Questions