How do I get the executable file of a java application?

I am new to the world of Java, but since I am familiar with C++, I already know a little about it. I created a simple dialog application in the IDEA environment and immediately the question is: how do I get the executable file . app (working in OS X) of my application. Or to be more specific-how do I run the program on another machine? My program:

import javax.swing.*;
import java.awt.event.*;

public class Dialog extends JDialog {
    private JPanel contentPane;
    private JButton buttonOK;
    private JButton buttonCancel;

    public Dialog() {
        setContentPane(contentPane);
        setModal(true);
        getRootPane().setDefaultButton(buttonOK);

        buttonOK.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onOK();
            }
        });

        buttonCancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        });

// call onCancel() when cross is clicked
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                onCancel();
            }
        });

// call onCancel() on ESCAPE
        contentPane.registerKeyboardAction(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    }

    private void onOK() {
// add your code here
        dispose();
    }

    private void onCancel() {
// add your code here if necessary
        dispose();
    }

    public static void main(String[] args) {
        System.out.println("Start");
        Dialog dialog = new Dialog();
        dialog.pack();
        dialog.setVisible(true);
        System.exit(0);
    }
}
Author: void, 2014-01-06

1 answers

As I understand it. app for mac is the same as. exe for windows...

Java has its own application format, namely. class and .jar is a zip archive with a set of .class and other information

In windows, there are ways out .jar get " clean .exe" or". exe with stuffed inside .jar and JRE " probably there is something similar for mac

In any case, you can collect .jar and run it on any OS

To build a jar in IDEA, go to File - >Project Structure->Artifacts there, click add - >Jar and configure the jar'nik assembly (in principle, there is an auto-configuration)

After that, go to Build->Build Artifacts, then a window will pop up with a choice of actions (build,delete, etc.)

P. s. to run on another machine, you need to have a JRE of the same or larger version than the bytecode in the jar. Everything starts like this >java -jar programm_name.jar as a rule .the jar file is already associated and is launched with a double click.

 4
Author: ProkletyiPirat, 2014-01-06 03:33:56