-3

I want to make a Java executable application. Just like executing an operation on double-click of the file. I don't want to load all the classes, compile the program and execute the .class file. Instead just an application; what all do I require. I wouldn't mind by starting of with a basic program which on double click launches some event.

djangofan
  • 28,471
  • 61
  • 196
  • 289
  • So you mean run a java program to launch class files. Seems like you are talking about a custom `ClassLoader` – 3kings Feb 21 '16 at 18:23
  • 1
    Here are some suggestions: http://stackoverflow.com/questions/147181/how-can-i-convert-my-java-program-to-an-exe-file – SevenOfNine Feb 21 '16 at 18:24

4 Answers4

1

I think the industry standard way to do this (assuming your not asking to generate a executable .jar file) is to use Launch4J .

Alternatively, you can generate a .jar file that is executable but it relies on your mime type file association on your system for it to be double-clickable. I think, most of the time, this is the way developers do it, because it works cross platform, and instead of double-clicking (when mime type is associated correctly), they execute it from a shell.

djangofan
  • 28,471
  • 61
  • 196
  • 289
1

Assuming you're on Eclipse, in a Windows env, I usually proceed compiling end exporting my project accurately.

Doesn't matter if it has ".jar" extension, you can "run" it just prompting something like this:

java -jar "path to my jar"

I usually create a simple batch.txt file, and put that line inside. Then i replace file extensione ".txt" with ".bat", and this way you could achieve the "double-clicked" styled start.

Otherwise, you could compile as "Runnable Jar" and it could be runned by "double-clicked" style app; but compile and be sure to point to the right mainclass in the manifest.

It's very very broad answer, but your question isn't specific enough.

Example:

1) Create simple Java Project

2) Put a new Class and name it "MainRunClass" with package com.runnable.testthis specific implementation:

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class MainRunClass {


    public static void main(final String[] args) {
        final JFrame parent = new JFrame();
        JButton button = new JButton();

        button.setText("Click me to show dialog!");
        parent.add(button);
        parent.pack();
        parent.setVisible(true);

        button.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                String name = JOptionPane.showInputDialog(parent,
                        "What is your name?", null);
            }
        });
    } 
}

3) Export as "Runnable Jar"

4) At prompt give it the "Launch Configuration put "Main Class\Project from the combolist, and the path of final export. You can leave "Export required jars and classes" in the same jar.

5) Double click it, or do a batch file as explained!

Black.Jack
  • 1,878
  • 2
  • 22
  • 39
0

You can't simply create exe file because of Java Applet. The postfix of Java files is jar, so you can create appliacation.jar :)

It depends where do you develope your application. In case you use NetBeans as I do, you just have to hit the hammer button (Build Project) and afterwards you can find your jar file in the folder dist.

Eclipse or other IDE works similarly.

Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183
0

Why would you want to make an exe file if you can make jar files? In Eclipse, you can export your projects as Runnable JAR files, which I would say is good enough.

In netbeans, as mentioned in other answers, you can hammer build it and find the jar in the dist folder.

Alternatively, if you just don't like that .jar extension, you can use iexpress to pack the jar inside an "installer", with hiding all dialogs, and setting the install command to java -jar program.jar. I am not quite sure if you can pack multiple classes and run the one with the main() function though.

John K
  • 123
  • 2
  • 10