Kanagaraj M
Kanagaraj M

Reputation: 679

Java jar output. where it goes?

I have a Swing application as jar file.

I am launching the application in 2 ways.

  1. In command prompt java -jar app.jar. launching & Working fine.

  2. double click app.jar. launching, but not working properly as expected. somewhere failed.

What would be the problem?

Where the logs(System.out.println()) will be printed in case of running the jar directly.

I have lot of sysouts. Will that cause problems?

Anyone please help in this regard.

Upvotes: 1

Views: 4974

Answers (5)

user617597
user617597

Reputation: 786

double click app.jar. launching, but not working properly as expected. somewhere failed.

Did you set the Application's Entry Point in the manifest file ?

PS:- Also Post your error message you are getting while double clicking the app.jar,

Upvotes: 0

Andrew Thompson
Andrew Thompson

Reputation: 168825

I would also recommend logging (over what I am about to suggest).

Having said that, it is possible for a trusted (or 'no sand-box') application to redirect System.out to wherever it is most useful. E.G. you might direct it to a ByteArrayOutputStream. When the results are required, write the entire content of the BAOS to a text area, or your own server, or.. wherever you like.


The same thing can be done with logging of course. I have UIs that add log messages to a list that is viewable by the end-user and included in bug reports. Logging is easily configured for level of detail and which parts of an app. to pay close attention to (by allowing different logging levels for different classes).

System.out.print(ln) is not easy to configure to extract specific details. It may result in a great deal of irrelevant output.

Upvotes: 0

Mohamed Mansour
Mohamed Mansour

Reputation: 40169

According to the Java Doc: http://download.oracle.com/javase/6/docs/api/java/lang/System.html#out

The "standard" output stream. This stream is already open and ready to accept output data. Typically this stream corresponds to display output or another output destination specified by the host environment or user.

For logging purposes, use some library such as log4j or Java Logging.

Upvotes: 2

Garbage
Garbage

Reputation: 1520

If you running jar by double clicking it, you will not be able to see the output of System.out.println(). You can either run the program from command line where standard output it console or you can write the outputs to file and check later.

I would recommend to use Apache Log4j for logging.

Upvotes: 1

jatanp
jatanp

Reputation: 4102

Double clicking on jar would invoke javaw (java - window mode) to run the main class defined in manifest.mf within the jar, and therefore, system.out would not be available to see.

I would recommend to replace System.out.println calls with a function which e.g.

public static void log(String text)
{
    System.out.println(text);
    // log it to some file
    writeToFile(text);


}

this will make sure that the log lines will be printed to file too, which could be used for debugging purpose. One note is printStackTrace won't print there !

Upvotes: 0

Related Questions