0

I followed this procedure to make a "fat" .jar file--one that contains external libraries inside executable .jar file.

But as often as not, and for no specific reason I can put my finger on, I get errors on both lines with ******* on them in \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>

The errors result no doubt from the instructions in the procedure in the link above to modify build.xml, which is a file created by Ant for the project.

The procedure adds <target> to build.xml, specifically including ALL of these lines:

  <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>

Specifically, the relevant line for me is:

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

(where Searchy is the user-supplied name for the "fat" .jar file).

Here is the error:

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)

No line of my code was flagged; if I simply RUN the project (F6), it's fine.

I have tika-app-1.9.jar as a Library, and it's huge, but in a prior version of this program, I was able to clean and build, including making a "fat" .jar file, with no problem.

Any thoughts about the cause and what to do about it?

* EDIT *

Part of the procedure is to right click build.xml (Files pane) and click Run targets | Other targets | package-for-store, which begins clean and build process.

Upon getting the error if I immediately repeat requesting package-for-store, a different error arises: Unable to delete file C:\Users\Dov\Google Drive\NetBeansProjects\SearchyTableSwing\store\Searchy.jar. If I try to delete it myself, I have to do so as administrator; even then I can't.

So I removed the lines added to build.xml and did a normal clean and build, which removed Searchy.jar from the store folder, which I then deleted.

I put the lines back into build.xml and requested package-for-store and got a fat jar file. No errors. Executes properly.

What is going on?

DSlomer64
  • 4,234
  • 4
  • 53
  • 88

1 Answers1

0

A very bad workaround is, before requesting package-for-store, delete the store folder. So far it works.

EDIT

Not any more.

Surely there's either a bug that needs reporting or a better solution.

EDIT

Ah, yes. There IS a bug right here along with comments:

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); }

But that's not what's happening here.........

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();
    }

Whatever... Is it Netbeans or Ant or ........ that needs fixing?

DSlomer64
  • 4,234
  • 4
  • 53
  • 88
  • Ant 1.9.6 does better. [See](http://stackoverflow.com/questions/32147796/ant-1-9-4-wont-clean-and-build-netbeans-8-0-2-project-using-java-8-gives-null) – DSlomer64 Aug 21 '15 at 22:03