In Netbeans, you want to edit the build.xml file to accomplish stuff like this. Some of it will be handled automatically, but you usually wind up tweaking that file. It’s an ant script, and the commentary in the file makes it pretty clear which rules you want to mess with. The downside is that you have to learn ant. Ant is basically an XML driven make utility, and messing with ant scripts is about the same level of complexity as messing with makefiles.
To get your project to run inside the IDE, right on the project, choose properties, select “run”, and you can fill in the main class, which will correspond to the java main you’ve been running directly. It also lets you fill in the expected stuff like starting directory, arguments, etc.
It helps to understand what is really needed for the standalone environment. What makes your project .jar file a standalone executable (other than containing all the needed class files and resources) is a single line in the manifest pointing to the main class - something like:
Main-Class: mypackage.MyMainClass
When you invoke “java [options] -jar myjar.jar [arguments]”, it starts up the jvm, instantiates that class, looks for a main method in it with the expected signature, and kicks it off, feeding it [arguments].
There’s lot of stuff that can be done in the manifest file. It’s worth doing some research on.
If you don’t want to get Netbeans to create the right manifest, you can actually simply extract the manifest file, diddle with it, and put it back in the jar. Jar files are actually zip files, so you can fiddle with them using your zip utility, provided you don’t screw up the expected structure or the manifest file. SIGNED jars are another story, but we needn’t go into that here.