Steve Ferguson
Steve Ferguson

Reputation: 802

Ant build producing 0-byte jar file

For months now I've been having an intermittent problem where, during my ant build, one of the jar files it produces is 0 bytes in size. This 0-byte jar file ends up getting packaged in my ear file, and the subsequent deployment fails. My project structure looks like this:

myProj
    myProj-common
    myProj-ejb
    myProj-web

The resulting build directory contains these files

lib
    myProj-common.jar  <-- sometimes 0 bytes
META-INF
   application.xml
   MANIFEST.MF
myProj-common.jar <-- never 0 bytes
myProj-ejb.jar
myProj-web.war

It is the myProj-common.jar file in lib that is 0 bytes. The one in the main build directory is always the correct size. It's unclear to me why I have two copies of the jar file in the end result. All of the ant build scripts were automatically generated by NetBeans.

I'm still learning the ins and outs of ant build files, so it's not entirely clear to me why they're so complex. I've written a somewhat minimal alternate build.xml file that I use for building the software in our Hudson environment on a Solaris server. That build never has this problem.

After upgrading from NetBeans 7.0.1 to 7.1.1, the problem has gotten a lot more frequent, and occurs whether I build the project inside of NetBeans or on the command line. The system where I'm having this problem runs Windows XP. With NB 7.0.1 I had a bad build perhaps one time in six. Now I have a -good- build maybe one time in ten.

Any pointers on where I should be looking to debug this would be most appreciated.

Upvotes: 1

Views: 1745

Answers (5)

andrei79et
andrei79et

Reputation: 1

I found a solution to this problem here: https://netbeans.org/bugzilla/show_bug.cgi?id=216033

In my case (Nebeans 8.0.2), it was enough to uncheck "Compile on Save" checkbox for my enterprise application. (Project properties -> Compile -> Compile on Save)

Upvotes: 0

moretti.fabio
moretti.fabio

Reputation: 1138

I know it's an old question, but sharing mi experience maybe help someone.

I've had the same issue with netbeans 8.0.2 on linux, my enterprise project lib folder look like this:

~/NetBeansProjects/myeeproject/build/lib $ ls -l
-rw-rw-r-- 1 user1 user1   16013 jan  5 11:52 my_lib.jar
-rw-rw-r-- 1 user1 user1 1489258 jan  5 11:52 my_ws_lib.jar
-rw-rw-r-- 1 user1 user1       0 jan  5 11:52 commons-lang3-3.1.jar
-rw-rw-r-- 1 user1 user1       0 jan  5 11:52 itextpdf-5.4.5.jar
-rw-rw-r-- 1 user1 user1       0 jan  5 11:52 primefaces-4.0.jar
-rw-rw-r-- 1 user1 user1       0 jan  5 11:52 primefaces-extensions-1.1.0.jar

and I cannot deploy the project to glassfish server. Doing repeately clean & build sometimes solve the problem, sometimes not, but I've found that deleting the 0-bytes jar and then doing a build (or a deploy) works every time. The problem is that if there's a file already in place netbeans simply does not copy the library, it doesn't check filesize, so deleting it force netbeans to do a fresh copy.

bye

Upvotes: 1

jonathan.ihm
jonathan.ihm

Reputation: 108

I had been having a similar issue happen to me lately as well. Just to summarize, I have an EAR file which contains a few EJB files and a WAR file. I am in a Windows 7 64-bit environment with Netbeans 7.2 and I run on a local JBoss 7 server.

I have seen this happen when I do one of two things.

  1. When I add a jar or library to the project and then remove it
  2. When I do a clean and build on the EAR file

I have encountered this issue so many times, it's not even funny now. I don't know if I have the exact same problem as you, but here is what solved my issue.

After removing any jars or libraries, you must clean and build. When I remove any JAR file or library, I see empty jars end up in my EAR's lib folder. Cleaning this will help reduce your issue.

Here's the main thing that happens to me.

  1. I cleaned ALL dependency projects and the EAR file itself and ensured all /dist folders were gone.
  2. I selected "Clean and Build" on my EAR file.
  3. I opened the EAR file in my /dist folder and saw that there will always be at least one JAR file in my /lib folder that is "empty" or size of zero.

Clean and Build ONLY the project(s) that has the size of zero. Then select "Build" and not "Clean and Build" on your EAR file. I hope this helps.

I can only theorize that the EJB is being built twice since it's a dependency in my WAR file, and it gets copied into the /lib folder during the second build. I have not done any ant debugging, only have found that this is a solution to my problem.

Summary: Clean and Build properly and make sure you are "Clean and Build"-ing the projects that end up as size 0 in your lib folder, then hit "Build" only on your EAR file.

Good luck!

Upvotes: 0

Steve Ferguson
Steve Ferguson

Reputation: 802

This appears to be a conflict with our whole-disk encryption software, PGP Desktop. Recently it was running in a degraded mode on my laptop, which slowed my builds down considerably, but then I never saw the problem arise. My speculation is that this left time for the lower level drivers to complete whatever actions they were taking and flush their write buffers. It looks like right now the jar file is getting copied before the write buffer flushes and therefore a 0-byte file is getting copied. Ant never sees an error, which is why there's no failure in the build process.

Unfortunately there's not much I can do, except perhaps modify the build script to throw in a delay before the jar file gets copied. Right now my workaround is to manually copy the jar after a full Clean and Build, then run Build (as opposed to Clean and Build), which only takes a few seconds to repackage the ear file.

I think the reason the problem got more prevalent when I upgraded NetBeans is that some change in the IDE made the builds run faster, and thus I ran into the buffering problem more often.

Upvotes: 0

gareth_bowles
gareth_bowles

Reputation: 21130

You should be able to figure out what's happening by executing Ant with the -d (debug) and -v (verbose) flags. You could either add these flags in NetBeans, or execute the build file generated by NetBeans from the command line.

Upvotes: 0

Related Questions