0

I want to include resources fils (images, textfiles...) in a JAR. I added my asset folder to the classpath, so my program works fine when I run it in netBeans.

But if I build the project, I receive an error :

Not copying library C:\Users\Flow\Desktop\cp , it's a directory.

Is it a normal error ?

So I tried to add assets manualy like that :

<target name="-post-jar">
        <jar destfile="dist/MonProjet.jar" update="true">
            <fileset dir="C:/Users/Flow/Desktop/cp">
                <include name="assets/*"/>
            </fileset>
        </jar>
</target>

But it does not work. Do I something wrong ? Sorry for my english and thank you for help.

flow
  • 4,828
  • 6
  • 26
  • 41

1 Answers1

1

Don't place the files on your desktop. Go to the Source folder of your project and copy it in that folder. In NetBeans, any resources you place in the src tree will be automatically copied over to the classes tree when you do a Build (or Clean and Build), except those files matching the "Exclude From JAR File" skeletons specified in Project -> Properties -> Build -> Packaging. So if you pasted it there it should be in your jar file.

Your directory structure should now look like this:

Project0  
  -build  
      --classes  
          ---asset  
          ---project0  
      --empty  

  -nbproject  
      --private  

  -src  
      --asset  
      --project0  

  -dist  
  -test 

Source: http://www.coderanch.com/t/511437/java/java/Adding-images-Jar-Files-NetBeans

DominikAngerer
  • 6,354
  • 5
  • 33
  • 60