Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't NetBeans find CopyLibs for some of my projects?

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.

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.

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)

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.

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.

I'm posting here in the hopes that:

  • 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.
like image 643
Henry Keiter Avatar asked Jun 06 '13 22:06

Henry Keiter


3 Answers

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.

In NetBeans, go here:

Tools > Options > Miscellaneous > Ant

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

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.

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.

I still don't know why this happened in the first place, or why it only seems to affect certain projects.

like image 126
Henry Keiter Avatar answered Oct 24 '22 08:10

Henry Keiter


I had NetBeans 7.1.2 on my Mac, uninstalled it, and then installed 7.3.1. I got the same errors. Here's what I had to do to fix: Go to

NetBeans menu > Preferences > Java tab > Ant subtab > Properties

I noted that the properties still had the old number for the app, so I had to change the 7.1.2 to 7.3.1, and then it worked.

enter image description here

Thanks for putting me on the right track!

like image 25
james.garriss Avatar answered Oct 24 '22 06:10

james.garriss


Background Info: The Ant properties are held in the build.properties file in a user directory. This varies dependent on platform but can be found by looking in the nbproject/private/private.properties file. Then look at the path under user.properties.file and have a look in the file pointed to - you can see the paths used in the Ant build - and whether they are correct.

like image 37
John Stevenson Avatar answered Oct 24 '22 06:10

John Stevenson