2

Ok, just listen to me before you close this thread or answer somethin completely out of topic. I have checked absolutely every solution. I have read every other similar SO topic and tried everything they say there. I'm using NetBeans and yes it does run my program succesfully ALSO my command promt RUNS PERFECTLY my program. I get "Could not find the main class: Main. Program will exit." ONLY when I am trying to double click jar. YES I HAVE Manifest file and it tells where my Main class is. I have even tried to create new project with only Main class which creates just one frame, and then build it, but still same error.

Here is my Main class (only class) which is in default package:

public class Main {

    public static void main(String[] args) {
        JFrame frame = new JFrame("Test");
        frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        frame.setVisible(true);
        frame.setBounds(450, 170, 400, 400);
    }
}

and here is manifest file:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.7.0_02-b13 (Oracle Corporation)
Class-Path: 
X-COMMENT: Main-Class will be added automatically by build
Main-Class: Main
Rohit Malish
  • 3,209
  • 12
  • 49
  • 67
  • 2
    Check your jar file association in your OS and see what command it runs when you "open" a jar file. – Ryan Stewart Apr 27 '12 at 17:44
  • Edited my post and added my class and manifest. How do I check my jar file association in my OS? – Rohit Malish Apr 27 '12 at 17:48
  • Do you have or not have a new line character on the Main-Class line? I forget which one you need, but you either have to have or can't have a new line there... – rooftop Apr 27 '12 at 17:54
  • 1
    @RohitMalish have you read this question? http://stackoverflow.com/questions/5428079/could-not-find-the-main-class-when-double-clicking-jar-file – Colin D Apr 27 '12 at 17:55
  • I have empty line in the end of manifest. Yes I have read and tried that command promt line and it shows me jarfile="C:\Program Files (x86)\Java\jre6\bin\javaw.exe" -jar "%1" %* – Rohit Malish Apr 27 '12 at 18:00

1 Answers1

2

After long and stressful time trying to find solution I FINALLY discovered what was wrong. So as you see for some reason NetBeans uses JDK7 as default but to run .jar file my system uses JRE6. So I changed my NetBeans settings to use and compile with JDK6 and got it to work. Also my code had diamond operator which are not supported in JDK6.

Rohit Malish
  • 3,209
  • 12
  • 49
  • 67
  • This worked for me. I had an older version 6 of icedtea still installed on Ubuntu. I removed the old jdk and jre packages for version 6. –  Oct 20 '12 at 19:55