.jar file keeps giving me " could not find the main class". Program will exit.

.jar file keeps giving me " could not find the main class". Program will exit.

Hi I have been having problems with this on both netbeans and eclipse even with a simple file that displays a jframe with a jlabel on it. My netbeans's project properties clearly sets testing2.hihi as my Main class and I have clean and build it which produces a .jar file in my dist folder. When I double click on it, it gives me the message" could not find the main class. Program will exit." However, if I choose to run it from the command prompt "java -jar hello2.jar" it will run as normal! Can anyone help me with this? Thanks alot!

  package testing2;

public class hihi extends javax.swing.JFrame {

/**
 * Creates new form hihi
 */
public hihi() {
    initComponents();
}

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

    jLabel1 = new javax.swing.JLabel();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    jLabel1.setText("hihi");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGap(50, 50, 50)
            .addComponent(jLabel1)
            .addContainerGap(334, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGap(33, 33, 33)
            .addComponent(jLabel1)
            .addContainerGap(253, Short.MAX_VALUE))
    );

    pack();
}// </editor-fold>

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    /*
     * Set the Nimbus look and feel
     */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /*
     * If Nimbus (introduced in Java SE 6) is not available, stay with the
     * default look and feel. For details see
     * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(hihi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(hihi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(hihi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(hihi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /*
     * Create and display the form
     */
    java.awt.EventQueue.invokeLater(new Runnable() {

        public void run() {
            new hihi().setVisible(true);
        }
    });
}
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
// End of variables declaration
View Answers

June 4, 2012 at 5:29 PM

import java.io.*;
import java.util.jar.*;

public class CreateJar {
  public static int buffer = 10240;
  protected void createJarArchive(File jarFile, File[] listFiles) {
    try {
      byte b[] = new byte[buffer];
      FileOutputStream fout = new FileOutputStream(jarFile);
      JarOutputStream out = new JarOutputStream(fout, new Manifest());
      for (int i = 0; i < listFiles.length; i++) {
        if (listFiles[i] == null || !listFiles[i].exists()|| listFiles[i].isDirectory())
      System.out.println();
        JarEntry addFiles = new JarEntry(listFiles[i].getName());
        addFiles.setTime(listFiles[i].lastModified());
        out.putNextEntry(addFiles);

        FileInputStream fin = new FileInputStream(listFiles[i]);
        while (true) {
          int len = fin.read(b, 0, b.length);
          if (len <= 0)
            break;
          out.write(b, 0, len);
        }
        fin.close();
      }
      out.close();
      fout.close();
      System.out.println("Jar File is created successfully.");
    } catch (Exception ex) {}
  }
  public static void main(String[]args){
    CreateJar jar=new CreateJar();
    File folder = new File("C://Answers//Examples");
      File[] files = folder.listFiles();
    File file=new File("C://Answers//Examples//Examples.jar");
    jar.createJarArchive(file, files);
  }
}









Related Tutorials/Questions & Answers:
.jar file keeps giving me " could not find the main class". Program will exit.
.jar file keeps giving me " could not find the main class". Program will exit... click on it, it gives me the message" could not find the main class. Program... netbeans's project properties clearly sets testing2.hihi as my Main class and I have
How to eliminate error," Could not find the main class: filecopy.FileCopy. Program will exit." ?
How to eliminate error," Could not find the main class: filecopy.FileCopy....) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) Could not find the main class: filecopy.FileCopy. Program will exit. Exception in thread "main" Java
Advertisements
could not find the main class programm will exit - error
could not find the main class programm will exit - error  when i tried to run the below mentioned programmed it gives a error states - could not find main class programm will exit. class Car { String name: String Color
How to run java swing application from jar files .
setup file .As per my knowledge i have to run .jar file from dist folder of netbeans but when i am trying to run from there i am getting error "Could not find the main class program will exit" from "java virtual machine". Plz help me
Error 500-Server are not find the jar file in the program of upload the file - JSP-Servlet
Error 500-Server are not find the jar file in the program of upload... a program to upload a file.I include the commons-fileupload-1.2.1.jar file in lib...)]: Servlet class UploadFile for servlet one could not be loaded because
how to delete a jar file from mobile by using j2me program.
how to delete a jar file from mobile by using j2me program.  When i'll update a new version jar in mobile. Then i want to delete that old jar which is previously present in mobile. How to do
File path for jar file
jar file of that application, unfortunately it is giving the error that resource...File path for jar file  Hi Experts, I have created one eclipse... handle the paths given to program in jar files
jar file
jar file  steps to create jar file with example
jar file
jar file  jar file where it s used
jar file
jar file  how to create a jar file in java
JAR FILE
JAR FILE  WHAT IS JAR FILE,EXPLAIN IN DETAIL?   A JAR file... and applications. The Java Archive (JAR) file format enables to bundle multiple... link: Jar File Explanation
jar file
jar file  how to run a java file by making it a desktop icon i need complete procedur ..through cmd
program to display frequency count of each word in a file using Hashmap, Hashset and streamtokenizer.plz help me out ..
program to display frequency count of each word in a file using Hashmap... java.util.*; class test1 { public static void main( String args[])throws... the words in file content.   Program : by HashSet and StringTokenizer
org.apache.commons.collections15.Transformer jar file
org.apache.commons.collections15.Transformer jar file  Dear, Please can you provide me the link for the following jar file: import org.apache.commons.collections15.Transformer; tahnks too much
jar file with html
jar file with html  I have a jar file. On double click it shows an applet page. Please tell me how to connect that applet into html or jsp page
JAR File - Swing AWT
JAR File   Is there anybody to solve my problem of not executing the JAR file? I have asked the question previously but I haven't got any answer yet. Please help me
Jar file - Java Beginners
will get answer i bulid a jar file of my project using netbeans but now problem is when i open that jar file in command prompt i got error exception in thread main please tell me how can i solve this error thanks and regards dumb
Listing the Main Attributes in a JAR File Manifest
Listing the Main Attributes in a JAR File Manifest       Jar Manifest: Jar Manifest file is the main... the information syntax with rule and restrictions. Main Attributes in Jar file
Viewing contents of a JAR File
the jar file operation through the given example. Program Result:ADS_TO_REPLACE_1 This program takes takes a jar file name which has to be viewed. It shows... Viewing contents of a JAR File     
jar file - Java Beginners
an application packaged as a JAR file (requires the Main-class manifest header)java -jar... it more usable,. JAR file size is very small as compared to the class file. So... archive file. Typically a JAR file contains the class files and auxiliary
How to create a jar file
a single executable jar of it... so pls tell me how it will b possible for me???   The given code creates a jar file using java. import java.io.*; import...(); System.out.println("Jar File is created successfully."); } catch (Exception ex
Executing JAR file - Swing AWT
created the JAR file of my project with the Manifest File including my Main... Manifest.txt secl/*.class and my jar file is created. But there is a problem, when... error msg dialog box is shown: Could not find the main class.Program
struts jar file problem
struts jar file problem  hi.. I'm using struts-core-1.3.9.jar. it works well if am using ma application with internet but it shows me an error while initializing ActionServlet when i disconnected to Internet The error stack trace
Running Jar file in Windows
Running Jar file in Windows  Running Jar file in Windows
Extract Jar File
Extract Jar File  How to extract jar file?   Hi Please open the command Prompt and to the jar file and write the command jar -xvf JaraFileName.jar
Creating an executable jar file
Creating an executable jar file  When I try to create jar.exe through CMD, the manifest file created doesn't contain Main-Class attribute, even though it is included in text file used during creation of jar file
provide me the program for that ques.
provide me the program for that ques.  wtite a program in java there is a class readchar.the functionality of this class is to read a string from...*; class GetCharacters{ public static void main(String[] args
How to use JAR file in Java
to digitally sign the JAR file. Users who want to use the secured file can check... do not use JAR file, then they will have to download every single file one... in JAR files, then you just need to download one single file and Run it.ADS
answer me this program
answer me this program  Java Code to Maintain student record,Name... java.util.*; public class StudentExample{ String name; int age; int sub1; int sub2; int... average; } public static void main(String[]args){ Scanner input=new Scanner
answer me this program
answer me this program  Java Code to Maintain student record,Name... java.util.*; public class StudentExample{ String name; int age; int sub1; int sub2; int... average; } public static void main(String[]args){ Scanner input=new Scanner
Could not able to load jar file - WebSevices
paths of the jar files. when I run that batch it is giving me error like, "Failed to load Main-Class attribute class". How can I fix this error? Please...Could not able to load jar file  Hi, I tried to parse
how to convert a jar file into .exe file
how to convert a jar file into .exe file  hi, I want convert my jar file into executable file,urgently please help me
Creating JAR File - Java Beginners
a line to my manifest file (i.e. Main-Class: mypackage.MyClass..., which says, Failed to load Main-Class manifest attribute from H:\Stuff\NIIT\Java...Creating JAR File  Respected Sir, Thankyou very much for your
requesting for a jar file - Development process
requesting for a jar file  Sir Please send me a jar file of this sir , i need this package jar file org.apache.poi.hssf.usermodel for Excel reading /Writing in java please help me. thanks in advance....  Hi Friend
jar File creation - Swing AWT
in java but we can create executable file in java through .jar file.. how can i convert my java file to jar file? Help me...jar File creation  I am creating my swing applications. How can i
Create JAR file - Java Beginners
. But do let me know, isn't there any other way of making a JAR File. Simply like... to make a JAR file and run it easily on any computer. For that purpose i want to make my .class files to get converted into .jar file. More knowledge
Reading a file from Jar JAVA
Reading a file from Jar JAVA  I have added one excel sheet into a jar file. can anybody tell me how i can read that file. actually when i am running code from eclipse i able to read it but when i am adding that jar file
Reading a file from Jar JAVA
Reading a file from Jar JAVA  I have added one excel sheet into a jar file. can anybody tell me how i can read that file. actually when i am running code from eclipse i able to read it but when i am adding that jar file
creating a jar file - JSP-Servlet
creating a jar file  Can you give me detail answer 1. i am having a servlet.class file in classes folder 2. web.xml file my questions are 1. where to place the html or jsp files 2. how to create a jar file and how can
How to Unjar a Jar file in Java
A JAR file is a collection of Java class files that contains images, methods, texts, etc into one file. All these class files are compressed and archived.... JAR file in Java simplifies distribution and makes it available across
Creating JAR File - Java Beginners
me, in letting me know, as to how to create JAR file from my JAVA source or class files. And what is this manifest file, and what changes needs to be done... main(String[]args){ CreateJar jar=new CreateJar(); File folder = new File
java jar file - Java Beginners
java jar file  How to create jar Executable File.Give me simple steps...(); System.out.println("Jar File is created successfully."); } catch (Exception ex) {} } public static void main(String[]args){ CreateJar jar=new CreateJar
Changing Executable Jar File Icon
Changing Executable Jar File Icon  I have created an executable jar file for my java program and the icon that appears is the java icon. I will like...;Hi, You may use JSmooth to create executable java file and also associate icon
What is a JAR file in Java
size. You can make the jar file executable by collecting many class file of your... What is a JAR file in Java       JAR file is the compressed file format. You can store many
Java Jar File - Java Beginners
Java Jar File  What is a Java JAR file ..and how can i open a .jar file in Java?  Just create a Jar file and Double click on it, it will automatically runs main method in that Jar : to create Project as JAR
Apache HSSF Jar file location
Apache HSSF Jar file location  where can i get jar files for apache hssf
Please explain me the flow of this program..
Please explain me the flow of this program..  // Substring replacement. class StringReplace { public static void main(String args[]) { String org = "This is a test. This is, too."; String search
Jar file creation - Swing AWT
Jar file creation  i have developed a swing application using Net... the application i gets a JAR file a lib file is also created in dist folder..this wrks fine using IDE 1.Now i want to give the application as a jar file
including jar file in maven pom.xml
including jar file in maven pom.xml   Hi, I want to include a jar file from the WEB-INF/lib folder. Please let's know how to to do this? Thanks.... Add the following code into your pom.xml file and the error will go away
plz help me find a program
plz help me find a program  plz help..i want a source code in jsp for order processing

Ads