java.io.Console support in Eclipse IDE
I assume you want to be able to use step-through debugging from Eclipse. You can just run the classes externally by setting the built classes in the bin directories on the JRE classpath.
java -cp workspace\p1\bin;workspace\p2\bin foo.Main
You can debug using the remote debugger and taking advantage of the class files built in your project.
In this example, the Eclipse project structure looks like this:
workspace\project\
\.classpath
\.project
\debug.bat
\bin\Main.class
\src\Main.java
1. Start the JVM Console in Debug Mode
debug.bat is a Windows batch file that should be run externally from a cmd.exe console.
@ECHO OFF
SET A_PORT=8787
SET A_DBG=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=%A_PORT%,server=y,suspend=y
java.exe %A_DBG% -cp .\bin Main
In the arguments, the debug port has been set to 8787. The suspend=y argument tells the JVM to wait until the debugger attaches.
2. Create a Debug Launch Configuration
In Eclipse, open the Debug dialog (Run > Open Debug Dialog...) and create a new Remote Java Application configuration with the following settings:
- Project: your project name
- Connection Type: Standard (Socket Attach)
- Host: localhost
- Port: 8787
3. Debugging
So, all you have to do any time you want to debug the app is:
- set a break point
- launch the batch file in a console
- launch the debug configuration
You can track this issue in bug 122429. You can work round this issue in your application by using an abstraction layer as described here.
Eclipse Switch focus to console on Run
You can change to a view with the keyboard shortcut Alt+Shift+Q, release keys, and then wait for a moment and you will get a pop-up of views to select:
If you then press C the console will open. You don't have to wait for the pop-up if you don't want to.
If you want to change to the console often, perhaps a shorter key sequence.
In Preferences choose General -> Keys, then scroll or use filter to find Show View (Console) and you can change the shortcut:
Output to Eclipse console from jar running externally
- Run it from the command line.
- run it from another Java program as a separate JVM process, and capture the InputStream, OutputStream, and ErrorStreams for input and output.
Related Topics
Variable Is Accessed Within Inner Class. Needs to Be Declared Final
Gson - Convert from JSON to a Typed Arraylist<T>
Https Get (Ssl) with Android and Self-Signed Server Certificate
How to Create the Directory Error
How to Use JavaScript with Selenium Webdriver Java
What Could Cause Java.Lang.Reflect.Invocationtargetexception
How to Access an Iteration-Counter in Java's For-Each Loop
Why Is the Max Recursion Depth I Can Reach Non-Deterministic
How to Run Certain Task Every Day at a Particular Time Using Scheduledexecutorservice
The Literal Xyz of Type Int Is Out of Range
How to Scroll a Scrollview Programmatically in Android
Android - Setting a Timeout for an Asynctask
How to View/Change Socket Connection Timeout on Linux
Spring JSON Request Getting 406 (Not Acceptable)
Convert Existing Eclipse Project to Maven Project
Is It Possible in Java to Access Private Fields via Reflection