Jump to content

Convert *.jar to *.exe build with Netbeans for to run under XP SP3


Dietmar

Recommended Posts

Hi,

I test some programs for to convert an Java file *.jar to *.exe for school.

This Java file Prim.jar is build with Netbeans 16 Ant under XP SP3 and works nice in this Netbeans 16 IDE under XP via Java 1.8.0_151 version.

This new converted prim.exe program should run under XP SP3, Vista, win7, win8.1, win10, win11.

Most convert programs do not work under XP SP3.

When you run it as a Console Application for example this program prim.exe, which generates Prim Numbers,

after finishing always closed the console at once, brrr..

Dietmar

EDIT: Is there any possibility, to make an prim.exe , that runs without any Java Environment?

For me it is strange as much as possible. When you build an prim.exe via C language, all those problems never happen.

 

Here is my file Prim.jar

https://ufile.io/l9xn8794

 

package prim;

import java.util.Scanner;


public class Prim {

 
    public static void main(String[] args) {
      


        Scanner scanner = new Scanner(System.in);
        System.out.print("Bis zu welcher Zahl möchten Sie die Primzahlen berechnen? : ");
        int n = scanner.nextInt();
        System.out.println("Die Primzahlen bis " + n + " sind:");
        for (int i = 2; i <= n; i++) {
            if (isPrimeNumber(i)) {
                System.out.print(i + " ");
            }
        }
    }

    public static boolean isPrimeNumber(int number) {
        if (number < 2) {
            return false;
        }
        for (int i = 2; i <= Math.sqrt(number); i++) {
            if (number % i == 0) {
                return false;
            }
        }
        return true;
    }
}

 

Edited by Dietmar
Link to comment
Share on other sites


After crazy a lot of tests I get it to run with the program jar2exe as console application. Now it runs also on XP SP3:cheerleader:.

Homepage is www.jar2exe.com .

I build it with Netbeans 16 Ant on java 1.8.0_151 .

The size of the prim.exe program is about 180 KB, but it runs on any windows without any Java.

Only for to build you have to convert the Prim.jar ==> prim.exe on the compi with your Netbeans, where this Prim.jar is build.

The error in all the other programs is, that the Main Class (here with name prim.Prim) cant be found.

Strange,  Main Class is there as prim.Prim .

Dietmar

EDIT: I succeed also with

Launch4j-3.8-win32.exe

For this, you have to give under Netbeans a Main Class for example prim.Prim .

But under Launch4j-3.8 you leave the Main Class unchecked, crazy.


E:\>prim.exe
Bis zu welcher Zahl möchten Sie die Primzahlen berechnen? : 100
Die Primzahlen bis 100 sind:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
E:\>

 

Edited by Dietmar
Link to comment
Share on other sites

I make some more tests:

With this Java Program, build just now with Netbeans 16 and JRE 1.8.0_151

also the via www.jar2exe.com build pong.exe runs only in an Java Environment.

So, Launch4j-3.8-win32.exe is the better choice, because it is free.

I do not succeed to make a pong.exe Program without any Java Environment but under Java 1.8.0 Environment it works

Dietmar

Here is all: Source, pong.jar, pong.exe

https://ufile.io/os4ynlxq

 

package pong;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;



 

public class Pong extends JPanel {
    int x = 0, y = 0, xa = 1, ya = 1;

    private void moveBall() {
        x = x + xa;
        y = y + ya;
        if (x + xa > getWidth() - 30 || x + xa < 0)
            xa = -xa;
        if (y + ya > getHeight() - 30 || y + ya < 0)
            ya = -ya;
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        g.setColor(Color.RED);
        g.fillOval(x, y, 30, 30);
    }

    public static void main(String[] args) throws InterruptedException {
        JFrame frame = new JFrame("Pong");
        Pong game = new Pong();
        frame.add(game);
        frame.setSize(300, 400);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        while (true) {
            game.moveBall();
            game.repaint();
            Thread.sleep(10);
        }
    }
}

 

Link to comment
Share on other sites

Hi,

just now I make small fun with game breakout.

I make this complete by my own and check with chatGPT

under Java Netbeans 16, Ant

Dietmar

PS: Here is the breakout.exe file. It runs under XP SP3.

For this, you need to have at least Java 1.8.0 installed.

https://ufile.io/ae3ygl6b

 

package breakout;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;

public class Breakout extends JFrame implements KeyListener {
int ballSize = 20;
int x = 150;
int y = 300;
int xa = 1;
int ya = -1;
int paddleX = 120;
boolean left = false;
boolean right = false;
int[][] bricks = new int[5][7];

int speed = 3;

public Breakout() {
    setSize(300, 400);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setVisible(true);
    setTitle("Breakout");
    setResizable(false);
    addKeyListener(this);
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 7; j++) {
            bricks[i][j] = 1;
        }
    }
    new Thread(() -> {
        while (true) {
            repaint();
            try {
                Thread.sleep(10);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    }).start();
}
public void paint(Graphics g) {
super.paint(g); // rufe die überschriebene paint-Methode der JFrame-Klasse auf
g.setColor(Color.RED);
g.fillOval(x, y, ballSize, ballSize);
g.setColor(Color.BLUE);
g.fillRect(paddleX, 380, 60, 10);
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 7; j++) {
if (bricks[i][j] == 1) {
g.setColor(Color.YELLOW);
g.fillRect(j * 40, i * 20, 40, 20);
}
}
}
if (left) {
paddleX = paddleX - 10;
}
if (right) {
paddleX = paddleX + 10;
}
if (paddleX < 0) {
paddleX = 0;
}
if (paddleX > 300 - 60) {
paddleX = 300 - 60;
}
x = x + xa;
y = y + ya;
if (x + ballSize > 300 || x < 0) {
    xa = -xa;
}
if (y + ballSize > 400 || y < 0) {

if (x > paddleX && x < paddleX + 60 && y + ballSize > 380) {
    double relativeIntersectY = (paddleX + 30) - x;
    double normalizedRelativeIntersectionY = relativeIntersectY / (30);
    double bounceAngle = normalizedRelativeIntersectionY * 5 * Math.PI / 12;
    xa = (int) (speed * Math.sin(bounceAngle));
    ya = -(int) (speed * Math.cos(bounceAngle));
    y = 380 - ballSize;
}



else {
System.exit(0);
}
}
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 7; j++) {
if (bricks[i][j] == 1 && x > j * 40 && x < j * 40 + 40 && y > i * 20 && y < i * 20 + 20) {
bricks[i][j] = 0;
                ya = -ya;
}
}
}
}

@Override
public void keyTyped(KeyEvent e) {

}

@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
left = true;
}
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
right = true;
}
}

@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_LEFT) {
left = false;
}
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
right = false;
}
}

public static void main(String[] args) {
new Breakout();
}
}






 

Edited by Dietmar
Link to comment
Share on other sites

Hi,

here is a very very first running famous game Moorhuhn from 1999,

build with Java Netbeans 16, Ant all by myself and check with chatGPT

Dietmar

PS: The game runs, klick on the "Moorhuhn" and they disappear^^.

You only need to have Java 1.4.0 installed, so may be it runs also under Win95:cheerleader:

https://ufile.io/qr48x85w

 

import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Random;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Moorhuhn extends JPanel implements MouseListener {
  private ArrayList<Target> targets = new ArrayList<>();
  private int score = 0;
  private Image background;

  public Moorhuhn() {
    background = new ImageIcon("background.png").getImage();
    addMouseListener(this);
    createTargets();
  }

  private void createTargets() {
    Random r = new Random();
    for (int i = 0; i < 10; i++) {
      int x = r.nextInt(400);
      int y = r.nextInt(400);
      targets.add(new Target(x, y));
    }
  }

  @Override
  public void paint(Graphics g) {
    g.drawImage(background, 0, 0, null);
    for (Target t : targets) {
      t.draw(g);
    }
  }

  @Override
  public void mouseClicked(MouseEvent e) {
    for (Target t : targets) {
      if (t.contains(e.getX(), e.getY())) {
        score++;
        t.setVisible(false);
        repaint();
        break;
      }
    }
  }

  @Override
  public void mousePressed(MouseEvent e) {}

  @Override
  public void mouseReleased(MouseEvent e) {}

  @Override
  public void mouseEntered(MouseEvent e) {}

  @Override
  public void mouseExited(MouseEvent e) {}
}

public class Main {
  public static void main(String[] args) {
    JFrame frame = new JFrame("Moorhuhn");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 400);
    frame.add(new Moorhuhn());
    frame.setVisible(true);
  }
}

class Target {
private int x, y;
private Image image;
private boolean visible;

public Target(int x, int y) {
this.x = x;
this.y = y;
image = new ImageIcon("target.png").getImage();
visible = true;
}

public void draw(Graphics g) {
if (visible) {
g.drawImage(image, x, y, null);
}
}

public boolean contains(int x, int y) {
int width = image.getWidth(null);
int height = image.getHeight(null);
return (x > this.x && x < this.x + width && y > this.y && y < this.y + height);
}

public void setVisible(boolean visible) {
this.visible = visible;
}
}

 

Edited by Dietmar
Link to comment
Share on other sites

Ohh..

soso much fun.

Here is version of my Moorhuhn from 1998 with sound:buehehe:,

not all ready but it can be done with a lot of work.

You have to copy the file sound.wav in the same folder as moorhuhnSound.exe

Dietmar

https://ufile.io/a0toemvw

 

import java.io.File;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Random;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Moorhuhn extends JPanel implements MouseListener {
  private ArrayList<Target> targets = new ArrayList<>();
  private int score = 0;
  private Image background;

  private Clip clip;

public Moorhuhn() {
    background = new ImageIcon("background.png").getImage();
    addMouseListener(this);

try {
  clip = AudioSystem.getClip();
  clip.open(AudioSystem.getAudioInputStream(new File("sound.wav")));
  clip.loop(Clip.LOOP_CONTINUOUSLY);
} catch (Exception e) {
  System.err.println(e.getMessage());
}



    createTargets();
  }

  private void createTargets() {
    Random r = new Random();
    for (int i = 0; i < 10; i++) {
      int x = r.nextInt(400);
      int y = r.nextInt(400);
      targets.add(new Target(x, y));
    }
  }

  @Override
  public void paint(Graphics g) {
    g.drawImage(background, 0, 0, null);
    for (Target t : targets) {
      t.draw(g);
    }
  }

  @Override
  public void mouseClicked(MouseEvent e) {
    for (Target t : targets) {
      if (t.contains(e.getX(), e.getY())) {
        score++;
        t.setVisible(false);
        repaint();
        break;
      }
    }
  }

  @Override
  public void mousePressed(MouseEvent e) {}

  @Override
  public void mouseReleased(MouseEvent e) {}

  @Override
  public void mouseEntered(MouseEvent e) {}

  @Override
  public void mouseExited(MouseEvent e) {}
}

class Target {
private int x, y;
private Image image;
private boolean visible;

public Target(int x, int y) {
this.x = x;
this.y = y;
image = new ImageIcon("target.png").getImage();
visible = true;
}

public void draw(Graphics g) {
if (visible) {
g.drawImage(image, x, y, null);
}
}

public boolean contains(int x, int y) {
int width = image.getWidth(null);
int height = image.getHeight(null);
return (x > this.x && x < this.x + width && y > this.y && y < this.y + height);
}

public void setVisible(boolean visible) {
this.visible = visible;
}
}

class Main {
public static void main(String[] args) {
JFrame frame = new JFrame("Moorhuhn");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
frame.add(new Moorhuhn());
frame.setVisible(true);
}
}





 

Edited by Dietmar
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...