0

我想在 JAR 中包含资源文件(图像、文本文件...)。我将资产文件夹添加到类路径中,因此当我在 netBeans 中运行程序时,它可以正常工作。

但是如果我构建项目,我会收到一个错误:

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

这是一个正常的错误吗?

所以我尝试像这样手动添加资产:

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

但它不起作用。我有什么问题吗?对不起我的英语,谢谢你的帮助。

4

1 回答 1

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

于 2013-05-19T09:47:11.100 回答