0

I made a small java program with eclipse and here I have a trouble. If I try to open it with double click or right click (I tried on Windows and linux) does nothing. But I used "java -jar ... " and it worked. How can I do that my program runs just by clicking on it?

Here is my code :

Main

Usuarios

Utiles---->

package main;

public class Utiles {

    private boolean n = false;

    public Utiles() {
        this.n = false;
    }

    public void limpia() {
        for (int i = 0; i < 100; i++)
            System.out.println();
    }

    public void salta() {
        for (int i = 0; i < 5; i++)
            System.out.println();
    }

    public void espacio() {
        for (int i = 0; i < 2; i++)
            System.out.println();
    }

    public static int countLines(String str) {
        if (str == null || str.length() == 0)
            return 0;
        int lines = 1;
        int len = str.length();
        for (int pos = 0; pos < len; pos++) {
            char c = str.charAt(pos);
            if (c == '\r') {
                lines++;
                if (pos + 1 < len && str.charAt(pos + 1) == '\n')
                    pos++;
            } else if (c == '\n') {
                lines++;
            }
        }
        return lines;
    }

}
Nicolas Filotto
  • 43,537
  • 11
  • 94
  • 122
F. Iván
  • 167
  • 1
  • 1
  • 12

2 Answers2

0

Jar default executable is not set. You can right click on the jar and select properties. Now select change and choose following C:\Program Files\Java\jre7\bin\javaw.exe.

This will make javaw as default app for jar executable.

Opv
  • 440
  • 1
  • 3
  • 17
0

Your program requires a terminal to display the text. When running with java -jar you have the terminal open, so you see what you expect. When there is no terminal, one needs to be opened. On windows this requires that you use java.exe (not javaw.exe).

Kayaman
  • 72,141
  • 5
  • 83
  • 121