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 :
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;
}
}
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.
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
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.