Home Answers Viewqa Java-Beginners .jar file keeps giving me " could not find the main class". Program will exit.

 
 


Tommy Tan
.jar file keeps giving me " could not find the main class". Program will exit.
1 Answer(s)      11 months ago
Posted in : Java Beginners

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 Pages:
.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
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
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
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
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
applicationDidEnterBackground Exit
applicationDidEnterBackground Exit  Hi, Provide me full code of applicationDidEnterBackground exit(0). Thanks   Hi, Here is the complete.... */ exit(0); return; } Thanks
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
a problem during add jar file javax.annotation.Resource
a problem during add jar file javax.annotation.Resource   when i use this jar file in my application i got this problem pls tell me about it Access... library C:\Program Files (x86)\Java\jre7\lib\rt.jar
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 - 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
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
need a jar file to come out of sleep mode
need a jar file to come out of sleep mode  Hi I need a jar file... explain what for I need to this file . there is an application program with name... mode .So I need a jar file to run and be hidden and check the incoming SMS
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
How to create a jar file with database connection
file but its not working pls help me.....   The given code creates a jar...How to create a jar file with database connection  Hello Everyone!!! Pls Help me in this... i have a program which has a database connection with ms
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
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
jar filw
jar filw  how can i run window based program using jar file
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
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
Runnable JAR
Runnable JAR  How to create runnable JAR file in eclipse ? Please provide me step by step demo... I am windows 7 user. I have made one jar file but when I double click it,it doesn't run. Why so
Runnable JAR
Runnable JAR  How to create runnable JAR file in eclipse ? Please provide me step by step demo... I am windows 7 user. I have made one jar file but when I double click it,it doesn't run. Why so
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
Java file delete on exit
the program terminates. createTempFile()- This method of File class create temporary  file. deleteOnExit()- This method of File class requests that the file...Java file delete on exit This section demonstrates you the use of the method
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
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
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
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
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
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
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
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
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
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
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
JAR Generation
JAR Generation  Hi, I have done this code. Can u pls tell me how to create a jar for this in eclipse, this is only a single java file? package... jxl.write.WritableWorkbook; import jxl.write.WriteException; public class DcpRep //implements
JAR Generation
JAR Generation  Hi, I have done this code. Can u pls tell me how to create a jar for this in eclipse, this is only a single java file? package... jxl.write.WritableWorkbook; import jxl.write.WriteException; public class DcpRep //implements
return 0 vs exit 0
return 0 vs exit 0  what is the difference between return 0 and exit 0 in c? i could not find any difference in their behaviour (both terminates the process execution) in a program
Viewing contents of a JAR File
the jar file operation through the given example. Program Result: This program... Viewing contents of a JAR File       This section shows you how you can read the content of jar file
jar file
jar file  how to run a java file by making it a desktop icon i need complete procedur ..through cmd
how can create a jar file - Java Beginners
how can create a jar file  plz any one help me which file can i create the jar file plz give exact command  Hi The basic format of the command for creating a JAR file is: jar cf jar-file input-file(s
Only change jar file icon - Java Beginners
Only change jar file icon  Dear Friend I know that how to create a jar file but i don't know How to change jar file Icon. I can change .exe file icon but i can't change .jar file icon okk, /// best help for me if you sent
Creating a JAR file in Java
. This program has been used the jar command "jar cf jar-file-name directory... Creating a JAR file in Java       This section provides you to the creating a jar file
quqtion on jar files
quqtion on jar files  give me realtime examples on .jar class files   A Jar file combines several classes into a single archive file. Basically,library classes are stored in the jar file. For more information,please go
How to "Get data froom MySQL DB on giving a value in a tex-box in a JSP file."
How to "Get data froom MySQL DB on giving a value in a tex-box in a JSP file."  Hi, How to get data from MYSQL Database tables on giving a "text... it in the same JSP file. Help me plz
Need to know struts1 all jar file names
Need to know struts1 all jar file names  Hi, My name is Neeraj, I want to know all the jar file names for struts1 and plz provide me the link to download these files. Thanks & Regards Neeraj

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.