Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print messages from running jar file?

Tags:

java

Lately I've been working on building two tools using Eclipse. I'm printing some messages to the console there (System.out.print). However, I've now constructed a .jar file for each tool, which I want to run on a different machine (no eclipse installed). Running this .jar does not provide me with the messages I'm printing.

What is the best way to print messages to the screen from a running .jar file? For example, how to print:

System.out.print("Results succesfully saved!");

I've googled quite a bit, but couldn't find any results.

like image 850
Maza89 Avatar asked Feb 22 '23 11:02

Maza89


1 Answers

System.out.print("Results succesfully saved!"); will work just as fine for a .jar-program. However, it requires the user to run it in a terminal so that he sees the stuff printed to standard output.

If this is not what you're after, then perhaps you want to have a look at JOptionPane which has a few static methods to graphically display messages like those.

This screenshot

enter image description here

is for instance produced by this snippet:

import javax.swing.JOptionPane;

class Test {
    public static void main(String[] args) {
        JOptionPane.showMessageDialog(null, "Results succesfully saved!");
    }
}
like image 101
aioobe Avatar answered Mar 03 '23 14:03

aioobe