LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 07-17-2012, 01:47 AM   #1
GanglyCloth
LQ Newbie
 
Registered: Jan 2012
Posts: 8

Rep: Reputation: Disabled
Question Program closes fine when run from cmd but .jar doesn't close.


Hello,

I`m developing a simple java application and I've run into a rather annoying issue. When I run my application from the command line using > java Main it behaves as expected, specifically when I close the window the program exits gracefully. However when I build it as a jar using > jar cfe app.jar Main Main.class Form.class it doesn't do anything when I hit the close button and I have to kill the process.

The app simply displays a randomly selected message if the app hasn't been run earlier in the day.

This is my main method.
Code:
public static void main(String args[])
{
    String message = "";
    boolean usedToday = false;
    usedToday = usedToday();
    message = getMessage(usedToday);
    Form.draw(message);
}
And the form class
Code:
public class Form {
    public static void draw(String message) {
        final Frame frm = new Frame("App");
        Label lbl = new Label(message);
        frm.add(lbl);
        lbl.setAlignment(Label.CENTER);
        frm.setSize(500, 200);
        frm.setBackground(Color.CYAN);
        frm.setVisible(true);
        frm.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                Main.writeTime();
                frm.dispose();
                System.exit(0);
            }
        });

    }
}
 
Old 07-17-2012, 02:03 AM   #2
GanglyCloth
LQ Newbie
 
Registered: Jan 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
The solution was simply to include the class file Form$1.class in the jar
>jar cfe app.jar Main Main.class Form.class Form$1.class
or
>jar cfe app.jar Main *
 
  


Reply

Tags
close, jar, java


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
script doesn't run in cron (runs from shell just fine) Timur Sakayev Linux - Software 6 02-26-2007 12:56 PM
How to run JAR from within Java program ?! EAD Programming 1 12-31-2006 07:11 PM
How to run script that doesn't terminate when shell closes? bjdea1 Linux - General 2 09-20-2004 10:20 PM
Gtk-Warning but program still works... I close konsole, program closes Laptop2250 Linux - Software 2 11-14-2003 11:18 PM
HLDS closes when I close telnet MarleyGPN Linux - General 1 04-26-2003 05:34 PM


All times are GMT -5. The time now is 12:25 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration