Netbeans 8.0.2中Ant文件中的错误来来往往,但没有.java源错误

时间:2015-08-18 23:07:08

标签: java netbeans ant

我跟着this procedure做了一个"胖" .jar文件 - 包含可执行.jar文件中的外部库的文件。

但是经常没有,并且由于没有特别的原因我可以把手指放在上面,我在\nbproject\build-impl.xml中的*******上出现了两行错误:

    <target depends="init,-init-macrodef-copylibs,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen" if="do.mkdist" name="-do-jar-copylibs">


********<j2seproject3:copylibs manifest="${tmp.manifest.file}"/>


        <echo level="info">To run this application from the command line without Ant, try:</echo>
        <property location="${dist.jar}" name="dist.jar.resolved"/>
        <echo level="info">java -jar "${dist.jar.resolved}"</echo>
    </target>



***************<copylibs compress="${jar.compress}" excludeFromCopy="${copylibs.excludes}" index="${jar.index}" indexMetaInf="${jar.index.metainf}" jarfile="${dist.jar}" manifest="@{manifest}" rebase="${copylibs.rebase}" runtimeclasspath="${run.classpath.without.build.classes.dir}">


                    <fileset dir="${build.classes.dir}" excludes="${dist.archive.excludes}"/>
                    <manifest>
                        <attribute name="Class-Path" value="${jar.classpath}"/>
                        <customize/>
                    </manifest>
                </copylibs>

错误无疑会从上面链接中的过程中的说明中导致修改build.xml,这是Ant为项目创建的文件。

该过程将<target>添加到build.xml,具体包括所有这些行:

  <target name="package-for-store" depends="jar">

        <!-- Change the value of this property to be the name of your JAR,
             minus the .jar extension. It should not have spaces.
             <property name="store.jar.name" value="MyJarName"/>
        -->

        <property name="store.jar.name" value="SCHEDULAR"/>

        <!-- don't edit below this line -->

        <property name="store.dir" value="store"/>
        <property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>

        <echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>

        <delete dir="${store.dir}"/>
        <mkdir dir="${store.dir}"/>

        <jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
            <zipgroupfileset dir="dist" includes="*.jar"/>
            <zipgroupfileset dir="dist/lib" includes="*.jar"/>

            <manifest>
                <attribute name="Main-Class" value="${main.class}"/>
            </manifest>
        </jar>

        <zip destfile="${store.jar}">
            <zipfileset src="${store.dir}/temp_final.jar"
            excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
        </zip>

        <delete file="${store.dir}/temp_final.jar"/>

    </target>

具体来说,我的相关内容是:

    <property name="store.jar.name" value="Searchy"/>

(其中Searchy是&#34; fat&#34; .jar文件的用户提供的名称。

这是错误:

ant -f "C:\\Users\\Dov\\Google Drive\\NetBeansProjects\\SearchyTableSwing" -Dnb.internal.action.name=rebuild clean jar
init:
deps-clean:
Updating property file: C:\Users\Dov\Google Drive\NetBeansProjects\SearchyTableSwing\build\built-clean.properties
Deleting directory C:\Users\Dov\Google Drive\NetBeansProjects\SearchyTableSwing\build
clean:
init:
deps-jar:
Created dir: C:\Users\Dov\Google Drive\NetBeansProjects\SearchyTableSwing\build
Updating property file: C:\Users\Dov\Google Drive\NetBeansProjects\SearchyTableSwing\build\built-jar.properties
Created dir: C:\Users\Dov\Google Drive\NetBeansProjects\SearchyTableSwing\build\classes
Created dir: C:\Users\Dov\Google Drive\NetBeansProjects\SearchyTableSwing\build\empty
Created dir: C:\Users\Dov\Google Drive\NetBeansProjects\SearchyTableSwing\build\generated-sources\ap-source-output
Compiling 11 source files to C:\Users\Dov\Google Drive\NetBeansProjects\SearchyTableSwing\build\classes
compile:
Copying 1 file to C:\Users\Dov\Google Drive\NetBeansProjects\SearchyTableSwing\build
Copy libraries to C:\Users\Dov\Google Drive\NetBeansProjects\SearchyTableSwing\dist\lib.
C:\Users\Dov\Google Drive\NetBeansProjects\SearchyTableSwing\nbproject\build-impl.xml:981: The following error occurred while executing this line:
C:\Users\Dov\Google Drive\NetBeansProjects\SearchyTableSwing\nbproject\build-impl.xml:825: 
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)
    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.GeneratedMethodAccessor284.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.GeneratedMethodAccessor284.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.GeneratedMethodAccessor284.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: 1 second)

我的代码没有标记出来;如果我只是运行项目(F6),那很好。

我有tika-app-1.9.jar作为一个图书馆,而且它很庞大,但在这个程序的先前版本中,我能够清理和构建,包括制作一个&#34; fat&# 34; .jar文件,没问题。

关于原因的想法以及如何处理它?<​​/ p>

*编辑*

部分程序是右键单击build.xml(“文件”窗格),然后单击Run targets | Other targets | package-for-store,它开始清理并构建过程。

如果我立即重复请求package-for-store,则收到错误后,会出现其他错误:Unable to delete file C:\Users\Dov\Google Drive\NetBeansProjects\SearchyTableSwing\store\Searchy.jar。如果我自己尝试删除它,我必须以管理员身份删除它;即使那样我也不能。

因此,我删除了添加到build.xml的行并进行了正常的清理和构建,从Searchy.jar文件夹中删除了store,然后删除了该文件夹。

我将这些行放回build.xml并请求package-for-store并获得一个胖jar文件。没有错误。执行得当。

发生了什么事?

1 个答案:

答案 0 :(得分:0)

一个非常糟糕的解决方法是,在请求package-for-store之前,删除store文件夹。到目前为止它的确有效。

修改

不再。

肯定存在需要报告的错误或更好的解决方案。

<强> 修改

啊,是的。有一个错误here以及评论:

Guess it would be worth fixing in the next release :->

... and a good NPE-checker of the IDE should have detected this, too :->

2015-02-04 10:15:06 UTC This is a situation that probably doesn't happen too often - source and target location of rename are on different file systems and an IOException occurs while copying. Still it's strange it hasn't been reported before. Thanks!

looking at the sourcecode (ResourceUtils.java line:439) a null-reference for "project" must be the culprit: a) try { copyUsingFileChannels(sourceFile, destFile); copied = true; } catch (IOException ex) { project.log("Attempt to copy " + sourceFile + " to " + destFile + " using NIO Channels" + " failed due to '" + ex.getMessage() + "'. Falling back to streams.", Project.MSG_WARN); }

但这不是这里发生的事情.........

b)

It would also crash in the streamCopy-fallback at the second location with a NPE because auf procect=null
    at line 439:
        private static OutputStream getOutputStream(Resource resource, boolean append, Project project)
            throws IOException {
        if (append) {
            Appendable a = resource.as(Appendable.class);
            if (a != null) {
                return a.getAppendOutputStream();
            }
            project.log("Appendable OutputStream not available for non-appendable resource "
                    + resource + "; using plain OutputStream", Project.MSG_VERBOSE);
        }
        return resource.getOutputStream();
    }

无论是......是Netbeans还是Ant还是........需要修复?