PDA

View Full Version : Creating an executable Java file for deployment


ItsMe
02-15-2010, 02:37 PM
Hi,

I'm working on a project in Java and I want to create a file containing the whole project that can just be run. I'm currently working out of Netbeans so just using the 'Run Project' option.

I see the 'Clean and Build' option in Netbeans, however I am unable to get my project running successfully using this. I believe one of the problems is around finding required files (such as images) used in the program as they do not appear to be being copied into the JAR file when it's built. They work in Netbeans as I have a working directory set.

How should required files be placed so there is a JAR file or JAR file and dependant files ready to run?

Any help would be much appreciated.

Many thanks.

cs_student
02-15-2010, 09:56 PM
Try adding the file to the src file. (make sure that you also put it in the netbeans ide src tree). Then use

MyClass.class.getResourceAsStream


To get the file.


cs_student

BubikolRamios
02-16-2010, 07:45 PM
I see the 'Clean and Build' option in Netbeans, however I am unable to get my project running successfully using this


In windows, go to task manager and kill any 'java' process that you see, then try 'Clean and Build' . It does not work even if files are where they should be coz they are held by that 'java' process. I suppose on linux is same thing.

ItsMe
02-17-2010, 04:58 PM
Hi guys,

Thanks for the suggestions. I have managed to get a test project built, with the JAR including the dependant files used.

I'm now having a problem when I try to run the JAR. Double clicking it to start it is giving the error "Could not find main class. Program will exit!", but runs fine using java -jar file.jar. The 'Main-Class' in the MANIFEST.MF file appears correct.

Any ideas why this would be?

Many thanks.