0

I have made a java application on netbeans. Ive tried converting it into .exe with the help of various softwares like exe4j and launch4j. But the problem is, these softwares take only 1 main class. My application has 3. Thus my application doesnt connect to the databsae !

Anmol Khanna
  • 95
  • 2
  • 9

2 Answers2

2

i personally use exe4j

in exe4j when you continue wizard you will get this kind of window

enter image description here

then you can click green + button to add your excitable jar file and in the genaral area you should specified the main class .in this example test

let's say your application name is newMDIApplication

in netbeans you have 3 classes

 newMDIApplication.class
 newJframe.class
 newJframe2.class

when your application start main method of newMDIApplication.class get executed .so when you make a jar file you should fill it's main method .

and in that exe4j window you should choose newMDIApplication as main class

Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
1

your question is little confusing .. the Mainclass means the class which contain public static void main(String[] args)

function void main is startup of the program. you can initialize your programs in void main..

void main function will called by JVM when execution has been started.. you can't use use multiple void mains because JVM gets confused with it lol

EDIT

now i understood your problem

first remove this code from all gui classes ..

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(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(NewJFrame.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 NewJFrame().setVisible(true);
        }
    });
}

find and add this code on your class constructor of all Gui classes, if your class name is NewJFrame then your class Constructor is like this

 public NewJFrame() {
        initComponents();
        setVisible(true);; // add this code

    }

if you having Gui classes only .. please add a Java Class and put public static void main function on it

Class AppleClass{

//import your classess here

//This is your main class

public static void main(String[] a){ 

//This function will execute first on program startup

//put your look and feel code here (optional, codes given below)

//Here you can put codes for which  GUI you need to show first

}

}

you can show GUI by creating its object

Syntax

ClassName objectname = new ClassName();

ClassName - Name of your GUI Class ;

objectname - any name

for example :

NewJFrame abc = new NewJFrame();

look and feel code

//  write it inside public static void main


 try {
            UIManager.setLookAndFeel(new NimbusLookAndFeel());
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(JavaApplication10.class.getName()).log(Level.SEVERE, null, ex);
        }

make sure these classes are imported

  • import java.util.logging.Level;
  • import java.util.logging.Logger;
  • import javax.swing.UIManager; import
  • javax.swing.UnsupportedLookAndFeelException; import
  • javax.swing.plaf.nimbus.NimbusLookAndFeel;

EDIT 3 - Converting into exe

  • Build executable jar , goto run menu-> Clean and Build Project(Project name)
  • Download Launch4j and run it
  • set Output exe file location
  • set Executable Jar location ( you can find it on dist folder in Project directory)
  • goto 'class path' tab uncheck 'custom path'
  • goto 'Single Inheritance' tab and uncheck 'Allow only a single......'
  • goto 'JRE' tab set min version-1.5.0_45 , max-version -1.8.0_45
  • click gear icon and save configration
  • click run button
Sajan
  • 813
  • 9
  • 14