1

I am a Beginner in Java GUI and am using Netbeans 7.3 to use Swing Components, the problem is that all was working fine, but one day when I Clicked Clean & Build and tested the JAR file, it was not executing, I ran it in the Netbeans and It is working fine.
Then I thought that it would be a problem of Build Properties so I compared build properties from a project which was working fine with Jar file but I cannot find any difference, The problem is that when I double-click the JAR file, no Error is shown, I tried many ways like executing it from cmd but It did'nt worked.
Can anyone help me out What could be missing, and one thing more that is I even tried to build my project on another computer through Netbeans but no use.

MMujtabaRoohani
  • 483
  • 4
  • 19
  • How are you trying to execute the file from command line? What OS are you running on? – jsedano Aug 12 '13 at 23:22
  • I am using Windows 8, and executing cmd, then in it browsing to the dist directory and then writing the name of jar file with extension – MMujtabaRoohani Aug 12 '13 at 23:28
  • 2
    try to run it this way: java -jar nameofJar.jar – jsedano Aug 12 '13 at 23:30
  • great suggestion, I tried and the exception was returned. – MMujtabaRoohani Aug 12 '13 at 23:37
  • Great, fix the exception and if you can run the jar from the command line but not by double clicking try this: http://stackoverflow.com/questions/7325676/java-can-run-jar-from-cmd-but-not-by-double-clicking – jsedano Aug 12 '13 at 23:40
  • 1
    Thanks for your help within 10 mins, I really appreciate, The exception was raised and the problem was solved no need of the link you gave. – MMujtabaRoohani Aug 13 '13 at 00:38

2 Answers2

1

Try to open your .jar with winrar, and check if the classes are being added to the .jar, If they are not being added probably is a bug from netbeans, I would advise to install netbeans 7.2, and then open your project again, and then regenerate the Jar File. I was having a similar problem with Netbeans 7.3

Abstract
  • 664
  • 1
  • 5
  • 15
1

I think you executing .jar file from different folder - not from where it was created? If so - that means your application can not find some files - pictures, etc. So if you have some files which application uses - create the folder named "lib" and place there your files - but not .jar file. For example:

File file = new File("/images/etc.png");

means that it is placed in lib/images directory. So your .jar file could be run from here:

C:/myTestApplications/myApp.jar

which contains also folder

C:/myTestApplications/lib/images

Try that.

Ernestas Gruodis
  • 8,567
  • 14
  • 55
  • 117