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?