For applications made using NetBeans Ide:-
- Netbeans while making your jar file adds the classpath of the libraries needed for your application to the manifest.mf file and creates the folder lib in the dist folder containing the jar files that your application needs to execute.
- If you copy and paste just the jar file and try to execute it it will raise an error, so instead of just copying the jar file copy the entire dist folder and then execute the jar. It will work.
- To add the path of class libraries that are missing just create a plaint text file and then add the class path of the libraries to it. for example if you are getting error for the missing class file org.apache.tools.bzip2.jar located under the xyz directory then you should add the variable as it is shown Class-Path: xyz/org.apache.tools.bzip2.jar and save the text file. Then you should execute the following command.
jar cfm "Your jar File" "The text file you edited" "the files to add into the jar"
- Now run the application using the command "java -jar application_name.jar" and it should work fine.