Re: Jar Command line
tutor5 wrote:
Hi, guys.
can anyone help me. i have created an executable jar file in my GUI
program. it works, i tried the same thing on another non-gui program
and it does not work.
can anyone help me on how can i do it for non-GUI programms.
Thanks
Try to make a short example program that you can post here (you should
be able to make it one class and one short file). Show us the jar file
(jar -tf jarFileName) and whatever error you get when trying to run it.
Without that, we cannot help you.
For example, here is a short GUI Java program:
package guisscce;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Main extends JFrame {
public static void main(String[] args) {
Main m = new Main();
m.add( new JLabel( "Hello World!"));
m.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
m.pack();
m.setVisible(true);
}
}
And here I show how I build it and run it correctly.
Brenden@Homer ~/Dev/misc/GuiSscce
$ javac -d build/classes src/guisscce/*.java
Brenden@Homer ~/Dev/misc/GuiSscce
$ ls build/classes/guisscce/
Main.class
Brenden@Homer ~/Dev/misc/GuiSscce
$ jar cfe sscce.jar guisscce.Main -C build/classes guisscce/
Brenden@Homer ~/Dev/misc/GuiSscce
$ jar tf sscce.jar
META-INF/
META-INF/MANIFEST.MF
guisscce/
guisscce/Main.class
Brenden@Homer ~/Dev/misc/GuiSscce
$ java -jar sscce.jar
Brenden@Homer ~/Dev/misc/GuiSscce
$