When running a JNLP application (for example), "Java console" is opened, containing the output of the program and a bunch of debug functionality.
Whether the console is opened or not, is determined in the settings in Java Control Panel.
Is there a way to enable & show this Java console programmatically during the program execution?
Or alternatively, is there any way to to enable this Java console during the program execution if it wasn't enabled at the program startup?
(I'm thinking that probably not but if there's a way that could be nice to know)
br, Touko
Andrew Thompson's answer is the right way to do this. My answer is the fast way, if you don't have time to implement a logging framework now:
If you have written your program without logging and you just want to see all those System.out.println messages, you can redirect them all to a text file.
Inside your main method, try this:
System.setOut(new PrintStream(new File("C:/logs/log.txt"));
You might want to include a complete path instead of a local file reference.
Related
I have a Java application run eclipse, user could input and output by "console"; in the meantime, I want to use another application to handle the "console", for example, another Java application to input "text string" into console, and then output saved into file. I am sorry firstly for the confusing question, do someone have any ideas?
You can run two applications at the same time using using the console. If you look in the console pane, there's a button on the top right that looks like a little compute monitor (Display Selected Console). When running two applications, you can toggle the console view for each application.
I want to clear the console output of the NetBeans console. We can clear it manually by using Ctrl+L.
Is it possible to do this programmatically, in Java?
Thank you very much
I think that it's not so simple.
The Netbeans console is not really a full system console.
I'd see a proper option - like getting the console reference using the Netbeans RPC binding, but your application would need to run as a Netbeans plugin or bundle. (so - don't do that, keep it simple)
For a shortcut (workaround) - you may try to use java.awt.Robot class to send a keyRelease event (Ctrl+L) while being focused in the console (effectively sending the Ctrl+L event to the focused component)
This is a poor solution because it doesn't actually clear anything, but it does push it out of the way to hopefully make it more readable.
System.out.print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
add or subtract "\n" to lengthen or shorten it depending on the size of the console window.
The application creates and displays various Swing widgets, and also writes debugging messages to System.out. If I start it as java -jar ...jar then I see it, but if I click on jar file in GUI I don't see the console. How to make it show console to user explicitly, e.g. on reaction to "View -> Debug output" menu item?
Expecting something that will pop up cmd.exe window on Windows, xterm/... on Linux, but it may be Swing window as well. How to do it the easily?
First don't use System.out to log, use some Logging framework to write logs in some file and to display the debugging logs open a new JDialog with JTextArea or JTextPane in it. Read the log file content and display that in the textArea. This way it will also solve platform dependency.
I think that you looking for CTRL + SHIFT + F1 works if is GUI visible here you can see output to the console, with Tree hierarchy of JComponents
AFAIK on Windows the console would be displayed on the first console output (i.e. System.out.printXXX), while on Linux it must be executed from console itself to do so. I'd rather create a separate window with a JTextArea (or something similar) to display the debug output. Normal users won't care about / need it, right?
that might be some kind of a silly question for you guys, but anyways: Is it possible to start the Java-console (as it is shown in Eclipse) parallel to the actual SWT-GUI?
The console contains an awful lot of debugging-information and I want my testers to be able to see what's currently going on. Obviously, they're not gonna use Eclipse...
Start your program using java instead of javaw.
Another way is that you abstract your logging mechanism so that it uses console if one is attached to the process (when started with java or within Eclipse) or puts the messages in a separate window the user can open if they want.
Run the application with the parameters:
-console -consoleLog
Is it possible to debug the applet loading process of the java plugin?
I don't want to debug my applet application, I want to debug the applet loading process of the java plugin2. I mean the jnlp/jar download, cache lookup, certificate check, etc. I know the java plugin is not open source, but it would help anyway.
I'm trying to solve JNLP2ClassLoader issues happening only within IE. It works with Google Chrome or Firefox. The error is not very reproducible, but one of the is "JNLP2ClassLoader.findClass: org.apache.log4j.spi.ThrowableInformation: try again...".
You can set the log level to trace, pressing 5 anytime in the java plugin console. Configure the plugin to open the console automatically and press 5 as soon as it opens. this will print a bunch of stuff that can or cannot be useful to you.
I know you can with eclipse if you put a breakpoint somewhere in one of the init methods. You should be able to run an applet from your debugger without needing a webpage.