Ant 1.9.4 won't clean and build Netbeans 8.0.2 project using Java 8; gives null pointer exception

一个人想着一个人 提交于 2019-12-13 02:14:43

问题


My code has no errors. If I choose F6 (Run) it executes fine. If I Clean it, there are no errors. But if I clean and build, I get these errors because of bug(s) in Netbeans 8.0.2 and/or Ant 1.9.4. The completely unacceptable workaround is to create a new project and copy all the files into it. This works for awhile. Then I have to do it again.

EDIT

I use tika-app-1.9.jar as library file. It is 45MB. If I remove it and instead use tika-parsers-1.10.jar and tika-core-1.10.jar as library files, I don't get this error BUT my program then can't properly process .PDF files. And with the huge library, the program has compiled successfully dozens of times and run as standalone (i.e., outside Netbeans) many more times.

END OF EDIT

EDIT 2

OK. I deleted replaced the two smaller library files with tika-app-1.10.jar and clean and build WORKED.

ONCE.

END EDIT

Please offer some insight into why it's happening and how to fix and prevent it or otherwise debug it. I have over 3000 lines of debug output but the bottom line, whether debug is selected or not is always these:

C:\Users\Dov\Google Drive\NetBeansProjects\Find\nbproject\build-impl.xml:994: The following error occurred while executing this line:
C:\Users\Dov\Google Drive\NetBeansProjects\Find\nbproject\build-impl.xml:838: 
java.lang.NullPointerException
    at org.apache.tools.ant.util.ResourceUtils.copyResource(ResourceUtils.java:439)
    at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:559)

Here's my project:

I haven't messed with build.xml or any other generated files.

I've restarted Netbeans 8.0.2 and looked for instances of JVM that might be running. There aren't.

Here's the Ant screen:

Here's more of the stack trace:

    at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:519)
    at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:480)
    at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:443)
    at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:409)
    at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:384)
    at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:322)
    at org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs.execute(CopyLibs.java:206)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at sun.reflect.GeneratedMethodAccessor61.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at sun.reflect.GeneratedMethodAccessor61.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:396)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at sun.reflect.GeneratedMethodAccessor61.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:435)
    at org.apache.tools.ant.Target.performTasks(Target.java:456)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
    at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:286)
    at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:555)
    at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)
BUILD FAILED (total time: 4 seconds)

Please note these lines that FOLLOW the BUILD FAILED line:

Could not load class (org.apache.tools.ant.taskdefs.repository.MavenRepository) for type mavenrepository
Could not load a dependent class (jdepend/xmlui/JDepend) for type jdepend
Could not load a dependent class (javax/media/jai/PlanarImage) for type image
Could not load class (org.apache.tools.ant.taskdefs.repository.MavenRepository) for type mavenrepository
Could not load a dependent class (jdepend/xmlui/JDepend) for type jdepend
Could not load a dependent class (javax/media/jai/PlanarImage) for type image

回答1:


Checking the related ResourceUtils, it seems the exception is occurring in a copy task (probably the one copying your library Jar file), specifically when trying to log an error before falling back to another copy mechanism.

Meanwhile checking Ant 1.9.5, it seems the problem was fixed, and the release notes mention this in Bug 57533 (NullPointerException FileUtil.rename / ResourceUtils.copyFile() if copyUsingFileChannels failed).

Therefore, I would try to upgrade to Ant 1.9.5 to see if the problem is resolved.




回答2:


I downloaded Ant 1.9.6 and made Netbeans use it as shown in the screen shot.

No problem with the error and huge library .jar after 3 quick clean and builds.

Then: a different error:

Attempt to copy C:\Users\Dov\Downloads\tika-app-1.10.jar to C:\Users\Dov\Google Drive\NetBeansProjects\Find\dist\lib\tika-app-1.10.jar using NIO Channels failed due to 'C:\Users\Dov\Google Drive\NetBeansProjects\Find\dist\lib\tika-app-1.10.jar (Access is denied)'.  Falling back to streams.
C:\Users\Dov\Google Drive\NetBeansProjects\Find\nbproject\build-impl.xml:994: The following error occurred while executing this line:
C:\Users\Dov\Google Drive\NetBeansProjects\Find\nbproject\build-impl.xml:838: 
java.io.FileNotFoundException: C:\Users\Dov\Google Drive\NetBeansProjects\Find\dist\lib\tika-app-1.10.jar (Access is denied)
    at java.io.FileOutputStream.open0(Native Method)

EDIT

The project folder, the dist folder, the lib folder, and the .jar library file all had red Xs on them. Only way to proceed: shut down Windows and then the .jar file goes away; clean and build works again--but for how long. Period.

Pretty inconvenient to not be able to delete the .jar file other than shutdown.

Hope the bug gets fixed soon.



来源:https://stackoverflow.com/questions/32147796/ant-1-9-4-wont-clean-and-build-netbeans-8-0-2-project-using-java-8-gives-null

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