Thursday, March 14, 2013

Exporting java projects from netbeans to eclipse

Yesterday, I had to create a simple java desktop application for performing some file based automation quickly. For this I used Netbeans that has Mattise RAD tool inbuilt(it is available for eclipse also, since it is rarely required, I haven't installed it there) to create a desktop java application that I intended to export as a standalone jar file.
However the finished jar file could not run anywhere else as it did not package the referenced libraries in itself.

Exporting a runnable java application from Netbeans does not works out of box, as you need to export the entire dist folder that contains the distributable .jar file as well as the lib folder containing the dependant jars. In order to do so, I devised the following method that saved me a lot of time.

  1. First, create an application in Netbeans and build it.
  2. Open eclipse and create an empty java project.
  3. Copy the source folder contents to create the equivalent project in eclipse.
  4. Copy the jars and set the build path to fix the compile errors occured by missing reference.
  5. Check whether the exported project works in eclipse.
  6. Finally export the eclipse application as a runnable jar.

There are other methods ; i.e: Changing the jar file manifest, copying the referenced jar contents into the final jar, but these are more error-prone than this one.

No comments: