Ant build producing 0-byte jar file - netbeans

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.

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

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.

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.

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.
When I add a jar or library to the project and then remove it
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.
I cleaned ALL dependency projects and the EAR file itself and ensured all /dist folders were gone.
I selected "Clean and Build" on my EAR file.
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!

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)

Related

Error while keeping .jar file in buildpath of project on 2 laptops

I am using 2 laptops with the eclipse workspace synced through OneDrive.
I am working on a program which uses JDBC, with SQL. When I add the Connector/J.jar file to the build path from one PC, it shows an error in the other PC, and doesn't run at all. Is there any option to solve it such that no errors will be shown on any of the 2 PCs??
I want both my PCs to have their drives as clean as possible, so is there any way that I can have no errors without putting both the .jar files in a directory like C:\mysql-connector-java-8.0.23.jar??
P.S. I do not know much about build paths, so please explain in a simple language.
Yes, put the jars into the project itself so that the paths will be relative to the project.

NetBeans 10: missing external libraries in dist/lib

I used to work with NetBeans 8 and when I used to "clean and build" my project, NetBeans used to put MyProject.jar in the directory dist/, and ALL the external libraries and projects in dist/lib/.
But recently, I've installed NetBeans 10 and after a "clean and build" only the file MyProject.jar is in dist/. I've found many discussions/blogs/etc. online to create a single jar file with all the external librairies inside, but it's not what I need.
How can I do that?
I found out that the file nbproject/build-impl.xml was really different. Hopefully, I still had this file from my former NetBeans 8 version and I replaced the new file by the old one and it works.
If someone has a better solution/explanation, I still take it.

Running imported projects on netbeans fails to build

When I export my project to a zip, and then try to import it on another computer I always get this error:
Created dir: C:\Users\martins0011\Documents\NetBeansProjects\Movicol\build\web\WEB-INF\classes
Created dir: C:\Users\martins0011\Documents\NetBeansProjects\Movicol\build\web\META-INF
Copying 1 file to C:\Users\martins0011\Documents\NetBeansProjects\Movicol\build\web\META-INF
Copying 63 files to C:\Users\martins0011\Documents\NetBeansProjects\Movicol\build\web
C:\Users\martins0011\Documents\NetBeansProjects\Movicol\nbproject\build-impl.xml:846: C:\Users\martins0011\Documents\NetBeansProjects\Movicol\web\WEB-INF does not exist.
BUILD FAILED (total time: 0 seconds)
What causes this error?
I fixed it creating the folder WEB-INF manually on the directory of the project... weird bug, but solved, I can run it now! thanks alot anyway Eric!
I had the same issue while building a web project(JSP) on netbeans 7.2, then I created the WEB_INF manually and the project was successfully rebuilt. Note that this missing file comes from GIT hub upon fetching the web project, at least in my case.
I had the same problem in this year (2020) and I solved by copying and adding the webinf file into the web file in my project. And it doesn't matter where you take this file(webinf) it'll work from every project you choose to copy it.

Why are packages suddenly greyed out in Eclipse?

I have been working on an inherited webapp project and a few hours ago I exported to war file. I imported from the war file on another system (Ubuntu) and noticed all the project's packages are greyed out. Some I can expand others I can't.
Deploying the project in a container works fine, and does show the updates I made, however I can't get at the packages, or files I edited.
I have researched online and gotten no closer to an answer so far.
Any reason as to what's happening? I use Eclipse 3.7 on both systems.
A war file only contains compiled classes. You won't find your source files in a war file. That's not what it's used for.
If you want to share code and project files between two machines, use SVN, Git or another version control system. Even with 1 machine, you should use it anyway.

hot deployment of large codebase to weblogic 10.3

I have a very large code base whose build.xml consists of so many jar, some war files. One .class file may refer to more than one jar file. I manually compile the code and deploy the .ear file using Ant into weblogic 10.3 application server. But this compilation and deployment takes around 10 to 15 mins time. Is there any way to escape this part? Means, when I modify any java class from ide, it would generate a .class file in bin folder. Can I take all the modified .class files from bin folder and directly deploy them on corresponding jar files without doing server restart? Any help would be appreciated.
Thanks in Advance,
I recommend taking Ant out of your iterative development process. Since you are already an Eclipse user, install Oracle Enterprise Pack for Eclipse and deploy/run your app from Eclipse. OEPE will take care to do the minimal amount of work possible at deploy time for a given set of changes.