Hi all,
I want to know how to give an .exe file for my java prg.
pla help me.

Dani AI

Generated

A quick, practical path forward (build a runnable JAR first, then choose how to turn that into an .exe). Several replies here pointed at wrapper tools () and older commercial/third‑party options (); was correct that Java source alone isn’t a Windows PE — you need a launcher or an AOT tool. Modern, built‑in tooling (the JDK’s jpackage) and popular wrappers each solve slightly different needs: small launcher, bundled runtime, or true native binary. (docs.oracle.com)

Example: a tiny, modern add program and the basic steps to make a runnable JAR.

// Add.java
import java.util.Scanner;
public class Add {
  public static void main(String[] args) {
    try (Scanner s = new Scanner(System.in)) {
      System.out.print("a: ");
      double a = s.nextDouble();
      System.out.print("b: ");
      double b = s.nextDouble();
      System.out.println("sum=" + (a + b));
    }
  }
}

Compile and package:

javac Add.java
jar cfe Add.jar Add Add.class
java -jar Add.jar   # test before packaging

(Manifest/Main‑Class behavior and the jar command are documented in the JDK tools docs.) (docs.oracle.com)

How to get an .exe from that JAR (three common approaches):

  • Wrapper launcher: tools such as Launch4j produce a small native .exe that launches your JAR; you can configure whether it requires a system JRE or bundles one. Good for simple distributions. (launch4j.sourceforge.net)
  • Platform installer / bundled runtime: jpackage (part of modern JDKs) creates platform installers or a single exe that can include a custom runtime image (it internally uses jlink/WiX on Windows). Note: jpackage must run on the target platform and Windows packaging requires the WiX toolset. (docs.oracle.com)
  • Native AOT executable: GraalVM’s native-image compiles a true native binary (very fast startup) but needs a native toolchain and extra config for reflection/dynamic loading. Use it when you must eliminate the JVM at runtime. (graalvm.org)

Troubleshooting notes: always test your JAR with java -jar first; bundling a JRE increases package size; jpackage/GraalVM builds are platform‑specific; dynamic reflection often needs explicit config for native images.

Recommended Answers

All 8 Replies

NativeJ is a program that can make an exe for your jar files for Windows users

Thanks for your prompt reply, but can you give me some code how i go about it?
give me a small java prg for adding 2 numbers and code for developing .exe.

Thanks a lot

import java.io.*;
class add
{
	public static void main(String arg[])
	{
		float c,a,b;
		try
		{	
			DataInputStream x=new DataInputStream(System.in);
			System.out.println("Enter two numbers");
			a=Float.parseFloat(x.readLine());
			b=Float.parseFloat(x.readLine());
			c=a+b;
			System.out.println("sum="+c);
		}
		catch(Exception e)
		{
		}
	}
}
commented: Read the rules about giving code before you post such shit. +0

I didn't see the dates at all. Sorry. : The OP has long gone.

what is the easiest way to make .exe in java.
i am a beginner, PL help me with full guide

Member Avatar for Member #814414

Next time, please make a new thread. This thread is very old.

If you are absolutely sure you want an .exe, and there are many reasons not to, try some of the links above or just searching the terms yourself.

And for reference you can't make a .exe from source code you implement in java.
Only .jar and then you can use a 3rd party program to package it in .exe.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.