Pages

Subscribe:

Ads 468x60px

Tuesday, August 16, 2011

How to build a fat jar using Netbeans

Hmm after long time with out blogging. Finally decided to add some posts to my blog. So in this post I would like to describe how to build a fat jar using NetBeans. Of course you can simply do it using Eclipse. But in Netbeans you can't actually directly build a fat jar. The jar which is build using NetBeans is not adding the libraries you've used for the project. The libraries are added to a folder called "lib" whenever you run the jar the "lib" folder must be in the same directory.

So lets get started building a fat jar using Netbeans. The first thing you have to do is clean and build the project.

Then go the Files view of the Project and open the build.xml file.

Then copy and paste the following code just before the " project" tag ends.

Download file from here DOWNLOAD FILE

Then it's almost done. Now in files view of the project right click build.xml file and then select Runtarget >> Other Targets >> package-for-store.

That's it now your fat jar has been created. Go to your project folder and check the folder called store. Inside that folder you can see your fat jar.

That's it now you know how to build a fat jar using NetBeans. If you need any help just put a comment. Cheers :)

38 comments:

  1. This one solved a problem of mine, mate :) Keep up the good work

    ReplyDelete
  2. When stealing an article, at least link the original.
    http://www.oracle.com/technetwork/articles/javase/single-jar-141905.html

    ReplyDelete
  3. @Unknown I didn't steal it. I got the script from one of my seniors.. Anyway thanks for reference.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Great Help !! Thanks a lot :)

    ReplyDelete
  6. very thanks, therefore I can access this article by way of google . Oracle web site does'nt apper in searching

    ReplyDelete
  7. I get this great post via stackoverflow, thanks a lot!

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. shows "unable to find application class name" for javafx desktop application.............plz help

    ReplyDelete
  10. Great Post. Followed the steps and it worked like a charm. Thanks.

    ReplyDelete
  11. Thanks a lot! Worked perfectly

    ReplyDelete
  12. Hiii...
    I am using NetBeans IDE 7.4. In which I am facing same problem.
    When I am trying same solution which is provided by author, I am not getting that option "Package-for-Store".

    Please HELP ME..!!!!
    Thanks in advance

    ReplyDelete
  13. hii..Aruna Karunarathna. i got a an error while ruuning the "one jar",error Could not found or load main class$(main.clss).i changed class name also stil its showing same error ,can you please tel me whtas wrong with me.,,Thank you

    ReplyDelete
  14. Shows "unable to find application class name" for javafx desktop application for me to. Could you help us?

    ReplyDelete
  15. @Krisz Seems like a netbeans bug, https://netbeans.org/bugzilla/show_bug.cgi?id=203287
    Check updating the netbeans IDE.

    ReplyDelete
  16. Hello,
    while including lib into jar file some of the jar of the lib folder not included into the packaging of jar file. please help why this is happening and what the solution.

    ReplyDelete
  17. Please, how do I indicate the first class to run in the build.xml file, given that my application has a main method for each class.

    ReplyDelete
  18. Please, how do I indicate the first class to run in the build.xml file, given that my application has a main method for each class.

    ReplyDelete
  19. I have done just fine the very first time I did, doing a Standalone Application Project. I have moved it to new Enterprise Application Client. Every dependencies resolved and Build successfully. But after modifying the bulild.xml correctly with the snippet needed and the value of the property changed to the Project name, it gives an error when "Package for Store":
    ant -f ... package-for-store
    Target "jar" does not exist in the project "..." . It is used from target "package-for-store".
    BUILD FAILED (total time: 0 seconds)

    ReplyDelete
  20. Well done, its really helped me. There is also a reference here
    https://www.oracle.com/technetwork/java/javamail/single-jar-141905.html

    ReplyDelete
  21. Have done all steps but jar fat file is not executing.Do you have any idea for the solution of this problem.Even simple jar file run.

    ReplyDelete
  22. Thanks alot.but how do i include a pdf file as well?

    ReplyDelete
  23. why is not working for me ? is there anything that i should check, please pm me in lusi.rhozalina@gmail.com

    ReplyDelete
    Replies
    1. You shouldn't put private information. What's the error you are getting?

      Delete
    2. It works, it happen because i used demo library for graphic. After i change the library. It works

      Thanks for your attention

      Delete