Add resources to a JAR

送分小仙女□ 提交于 2019-12-20 07:22:41

问题


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.


回答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



来源:https://stackoverflow.com/questions/16633244/add-resources-to-a-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!