NetBeans & Executable JARs - java

New to NetBeans dev here. When I first created my project and began compiling, I noticed that NetBeans had automatically created a dist/ directory under my project root and was creating an Executable JAR in that directory.
I've now been developing for several weeks, and added many resource files to my project, including a system log file, an embedded SQLite database, and several properties files. These are files that my program (a Swing app) needs to read/write from at runtime in order to function correctly.
I just noticed this morning that the Executable JAR in my dist/ directory is several weeks old, and that compiling my project doesn't update it. I am wondering if that's because there are now all these new resource files and NetBeans doesn't know how/where to package them for the automatically-created Executable JAR.
Does this mean that I'll have to tweak the build.xml myself? Or is there a NetBeans dialog I can get to where I can specify where to pacakge everything? And if NetBeans should be doing this automatically, what could be the reason that it stopped creating the JAR for me, and what can I do to force this functionality again?
I went into Project Properties >> Packaging and made sure that the JAR file directory was still dist/MyProgram.jar and that the checkbox Build JAR after compiling was still checked, so obviously something else is either breaking the build or messing with NB.
Thanks for any tips!

If "Compile on Save" is enabled, then your .jar file will only be generated when you do a "Clean & Build" (Just "Build" is not available when "Compile on Save" is enabled)

You need to Clean and Build within netbeans to update the file within your /dist directory.
I use Netbeans 7.0 and this solution works for me.

Related

Difference between Run in eclipse and going to the project folder and using the .jar

I'm trying to find more information on how eclipse handles Running a project.
I want to understand it more because I have an issue I'm currently having where apache-poi .jar files which have been included into the classpath of my project will work properly when the project is ran through eclipse, but will not be detected when going to the same projects folder and running the main jar file to start the program.
It gives me the error: java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Cell (although sometimes instead of Cell, it's Sheet)
What could I consult to understand what is going on here, and possibly solve this issue?
Your NoClassDefFoundError indicates that the library was not available while running the jar.
This depends upon how you are exporting your project into the jar file.
If you're using eclipse to do so, you can:
Export->Java->Runnable Jar to create a jar that includes its dependencies
Make sure to check Package required libraries into generated JAR.
This will make all your jars (in build path including apache-poi.jar) as a part of the final jar.
It runs from eclipse because libraries are on the build path of the eclipse which makes them available in the classpath.

netbeans not generating classes when build is issues, but the program runs when compiling

So I have been using netbeans and successfully was able to do generate jar file in the dist folder ( using clean & build).
Now suddenly this does not work. It generates a jar file that does not run. Upon inspection, I found that the jar file does not have classes in it ( only folder structure). I also noticed that the build folder does not have classes.
However, when I run it by clicking the green arrow, it runs and the build folder has classes. When I do Clean/build to generate the jar file in the dist folder, then the build folder resorts to empty classes and empty jar file.
Any idea? I restarted netbeans, did a refresh and all that but no luck
Please help
I found the solution for many people running into this issue. It is the missing eclipseLink Library

Java export a folder next to jar in eclipse

I want to make it so, that when I export my project, Eclipse would create .jar file as well as folders and other files I desire on the same path. I am making a game and I rely a lot on external files, be it animation images or scripts, and it is very annoying copy pasting same stuff over and over again, additionally to making the "run" option not viable.
You can use Eclipse File sync Plugin to solve your problem, basically
this plugin synchronizes your eclipse workspace files to any external
folder you configured:
FileSync plugin for Eclipse is a file synchronisation tool. The main
goal is to keep files outside of Eclipse projects in-sync with Eclipse
project files. The plugin works as builder in Eclipse and will
synchronize all changes on Eclipse project files with mapped external
folders. E.g. if a file is created, changed or deleted in Eclipse,
then the mapped (external) file will be created, changed or deleted
too.
http://marketplace.eclipse.org/content/filesync

Add python module to JAR classpath in Eclipse

I have a Java project that utilizes Jython to interface with a Python module. With my configuration, the program runs fine, however, when I export the project to a JAR file, I get the following error:
Jar export finished with problems. See details for additional information.
Fat Jar Export: Could not find class-path entry for 'C:Projects/this_project/src/com/company/python/'
When browsing through the generated JAR file with an archive manager, the python module is in fact inside of the JAR, but when I check the manifest, only "." is in the classpath. I can overlook this issue by manually dropping the module into the JAR file after creation, but since the main point of this project is automation, I'd rather be able to configure Eclipse to generate properly configured JAR automatically. Any ideas?
*NOTE*I obviously cannot run the program successfully when I do this, but removing the Python source folder from the classpath in "Run Configurations..." makes the error go away.
Figured it out, had to add the source folder with the Python module in it as a class folder in the Build Path project properties. Not sure if this next part is necessary or not, but since the module is not compiled, I added the folder again as "Attached Source" after adding the class folder.
Have a look at the maven-jython-compile-plugin and its demo project at http://mavenjython.sourceforge.net/ . It allows bundling jython with dependencies into a standalone jar.

How to automatically create jar in JBuilder

Have a project developed in JBuilder 2007.
I can create a jar with the compiled classes and resources by right-clicking on the project in Package Explorer and selecting Export, but is there a way to set-up the project to automatically generate the jar file, whenever the source changes ?
Ant ! Here's a link with a great example involving jbuilder. Once your ant file is completed, you jsut run it. It will do the same thing as an export. Want any more help ?

Categories

Resources