How to print messages from a running jar file?

Recently, I have been working on creating two tools using Eclipse. I print some messages to the console there ( System.out.print ). However, now I have built a .jar file for each tool that I want to run on another machine (without eclipse). Running this .jar does not provide me with the messages I am typing.

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

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

I searched a little Google, but could not find any results.

+4
source share
4 answers

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

If this is not what you need, then maybe you want to look at JOptionPane , which has several static methods for graphically displaying such messages.

This screenshot

enter image description here

for example, created by this fragment:

 import javax.swing.JOptionPane; class Test { public static void main(String[] args) { JOptionPane.showMessageDialog(null, "Results succesfully saved!"); } } 
+6
source

Do you make cans from the console? If not, try it.

+1
source

I'm not sure how this works for Linux, but for windows you have to go to the control panel, open the java settings, go to advanced. And select the Java console -> show console.

Of course, it is even better to use a log framework, for example Log4j instead of System.out.println. This way you can print both the file and the console.

0
source

Printing on the screen will mean the same as when executing your program β€œmore directly”. However, you might consider using a registration framework, as it offers you more flexibility if you want to customize your output.

0
source

Source: https://habr.com/ru/post/1380551/


All Articles