为什么 NetBeans 无法为我的某些项目找到 CopyLibs? [英] Why can't NetBeans find CopyLibs for some of my projects?

查看:19
本文介绍了为什么 NetBeans 无法为我的某些项目找到 CopyLibs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天早上我遇到了一个令人讨厌的问题,我花了几个小时试图追查它.我继承了两个 NetBeans 项目的一些代码,AB.它们都成功构建和运行;没有复杂的 Ant 构建任务;只是默认的 IDE 设置.

I ran into a nasty issue this morning that cost me several hours trying to trace it down. I had inherited some code with two NetBeans projects, A and B. They both build and run successfully; there are no complicated Ant build tasks; just the default IDE setup.

这两个项目共享大量代码,因此我将其分解为一个新的第三个项目,Common.在解析引用等之后,NetBeans 不会报告任何错误.一切似乎都很好.我毫不费力地构建了 Common 项目.然后事情变得很奇怪.

These two projects share a large amount of code, so I factored it out into a new, third project, Common. After resolving references and so on, NetBeans reports no errors. Everything seems fine. I build the Common project without a hitch. Then things get weird.

突然间,当我尝试构建项目 AB 时,它们编译就好了——但是在build,每个都以相同的错误中断:

Suddenly, when I try to build projects A and B, they compile just fine--but at the end of the build, each one breaks with the same error:

Copying 1 file to C:\Projects\projectName\build
C:\Projects\projectName\nbproject\build-impl.xml:723: The following error occurred while executing this line:
C:\Projects\projectName\nbproject\build-impl.xml:543: taskdef class org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs cannot be found
 using the classloader AntClassLoader[]
BUILD FAILED (total time: 3 seconds)

所有 .class 文件都显示在 build/classes 中,其他一切似乎都进行得很顺利,但没有任何东西进入 dist文件夹.于是我开始搜索 CopyLibs 问题.

All the .class files show up in build/classes, and everything else seems to have gone smoothly, but nothing makes it to the dist folder. So begins my search for CopyLibs issues.

人们建议确保 org-netbeans-modules-java-j2seproject-copylibstask.jarproject.properties 文件中被正确引用(它是),并且在 /.netbeans/version/build.properties 文件中也是如此(它是).库确实存在于它被引用的所有地方;事实上,NetBeans 似乎默认将这个 jar 的副本放入所有 Java 项目的 ./lib 文件夹中.我尝试制作全新的项目并手动引入源,但无济于事.我很困惑.

People suggested making sure that org-netbeans-modules-java-j2seproject-copylibstask.jar was referenced correctly in the project.properties file (it was), and in the <userhome>/.netbeans/version/build.properties file as well (it was). The library does exist at all the places it is referenced; in fact NetBeans seems to place a copy of this jar into the ./lib folder of all Java projects by default. I tried making brand-new projects and bringing the sources in manually, to no avail. I was mystified.

我在这里发帖是希望:

  • 也许有人可以让我深入了解这是如何发生的,以及如何避免.
  • 也许有人可以告诉我为什么只有某些项目会失败,即使所有项目都具有完全相同的 project.properties 文件或全新.
  • 将来遇到这个问题的人会过得更好.
  • Maybe someone can give me some insight into how this happened in the first place and how to avoid it.
  • Maybe someone can tell me why only certain projects break, even when all have exactly the same project.properties file or are brand new.
  • People with this problem in the future will have a better time of it.

推荐答案

我能在网上找到的最接近的解决方案是 此链接,其中仅包含部分解决方案.遵循该帖子中的说明不会解决问题,因为它遗漏了一些重要的内容.这是我最终偶然发现的解决方案.

The closest fix I could find online is this link, which only includes a partial solution. Following the instructions in that post will not fix the problem, because it leaves out some important stuff. Here's the solution that I eventually stumbled upon.

在 NetBeans 中,转到此处:

In NetBeans, go here:

Tools > Options > Miscellaneous > Ant

在窗口底部,有一个标有Properties 的框.粘贴以下内容:

At the bottom of the window, there's a box labeled Properties. Paste in the following:

libs.CopyLibs.classpath=C\:\\Program Files\\NetBeans 7.1\\java\\ant\\extra\\org-netbeans-modules-java-j2seproject-copylibstask.jar

NetBeans 7.1 替换为您的实际安装路径.这就是它的全部内容!棘手的是,当您单击 OK 时,NetBeans 似乎对该字段中的文本进行了一些解析.具体来说,它将反斜杠视为转义符,并且有时还会添加反斜杠.

Replace NetBeans 7.1 with your actual install path. That's actually all there is to it! The thing that makes it tricky is that NetBeans appears to do some parsing of the text in this field when you click OK. Specifically, it treats backslashes as escapes, and also sometimes adds backslashes.

这就是我花了这么长时间才找到的原因:我尝试了链接中的解决方案(例如 C:\Program Files\Netbeans 等),但没有奏效,但后来我回到这个窗口发现这个:C\:Program Files 等等.哦!"我想,我只是打错了!我真是个傻瓜!"所以我将它更正"为 C:\ 并再次尝试 - 仍然没有成功.事实证明,NetBeans 会添加一个反斜杠来转义 :,但只会删除它在此处找到的任何其他单反斜杠.

This is why it took me so long to find: I tried the solution in the link (e.g. C:\Program Files\Netbeans etc), and it didn't work, but later I came back to this window to discover this: C\:Program Files etc. "Oh!" I thought, "I just typed it wrong! What a fool I am!" So I "corrected" it to C:\ and tried again-- still no success. Turns out NetBeans will add a backslash to escape :, but will just delete any other single-backslashes it finds in here.

我仍然不知道为什么会发生这种情况,或者为什么它似乎只影响某些项目.

这篇关于为什么 NetBeans 无法为我的某些项目找到 CopyLibs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆