Intellij IDEA remotely debug java console program - java

I have a remote server with Java running to which i have SSH access.
I am writing an app on the local machine, building it with maven.
Is it possible to set the IDE Itellij IDEA to run my project remotely? The idea is : to build the jar, copy it to the server, and debug the process ( or something like that).
It would be nice of you to share the settings i need to setup.

This is what I usually do to debug my remote app.
Run the server on debug mode
This can be adding this particular line when you run your application server
-Xdebug -Xrunjdwp:transport=dt_socket,server=n,suspend=n,address=9999
for JDK above 1.4, you can use this
-agentlib:jdwp=transport=dt_socket,server=n,suspend=n,address=9999
After that, run your application server
SSH Tunneling
I'm not 100% sure that you can access to your application's port directly if you're using ssh connection (well, maybe there is a way ;) ). So, first we need to expose the port for debugging that we set on first step by running this command.
ssh -f user#personal-server.com -L 9999:personal-server.com:9999 -N
Setting up the IDE
You can follow the step that #SSJVegito has said, which basically, is to point the debugger to the port 9999. Open the debug configuration in your Idea, then Change the circled value to 9999. Then, happy debugging :D

I think it's possible, I was able to do such a thing with a local server I was using to deploy my application. And since you have access to the server, it should work for you as well.
What you need to do in IntelliJ is create a Remote configuration. To do that, open IntelliJ and next to the run button (on the left), you should have your configurations, designated by a down arrow. Click that arrow and click Edit Configurations. A new window should open. Click the + sign in the upper left corner and the select Remote. A new window should appear. We now need to set the host and the port which the server uses for debugging (if you are using tomcat, it is usually 8000; in tomcat, you can locate it by opening the catalina.bat file with a text editor and looking for the JPDA_ADDRESS property, which allows you to change the port). Give your configuration a name and press Apply.
Afterwards, you need to run your configuration in Debug mode. You need to select it from the configuration list and press the Debug button located to the right of the Run button.
More details here:
http://blog.trifork.com/2014/07/14/how-to-remotely-debug-application-running-on-tomcat-from-within-intellij-idea/comment-page-1/
http://eclipse.org/jetty/documentation/current/debugging-with-intellij.html
http://www.javaranch.com/journal/200408/DebuggingServer-sideCode.html
I hope this helps.

Related

Debug remote java application using Intellij

I am trying to debug remote java application in Intellij but unable to get sucess, The steps which I am doing is
Run>Edit Configuration> Defaults> Remote
What is/are I am missing?
First, create a new Remote debugging configuration:
ALT + U + R
Take note of the port which IntelliJ plans to listen in Tomcat. On my setup the port is 8000, which is the default and this should be fine for your setup as well. To change the Tomcat JPDA port, edit catalina.bat (or whatever your startup script is) and find a line which looks like the following:
set JPDA_ADDRESS=8000
Second, make sure that you are building your project with javac -g .... The -g option means that debugging information will be turned on in your Spring WAR.
Finally, when you start Tomcat, use catalina jpda start, which will tell Tomcat to connect the debugger to port 8000. When you want to connect to IntelliJ then use ALT + SHIFT + F9 and select your remote configuration from the menu. Of course, you should add some breakpoints, without which it doesn't make much sense to be in debug mode.
You don't need to edit the defaults. You need to use the [+] button to create a new Remote run configuration and specify its settings.

Websphere admin console not working

I have trouble opening the admin console for the websphere server. The server is up and running though, the application deployed and all. The only problem is with the console which gives a 404 error. Does anyone know how to fix this? Maybe reinstall/restore the console somehow?
Thanks.
You can try to reinstall the admin console :
Goto C:\[PATH TO PROFILE]\bin
Then run the Jython commands, first to cleanup, then to reinstall :
wsadmin -lang jython -f deployConsole.py remove
Wait till the admin-console is uninstalled.
Now reinstall of administrative console (isclite) will complete without errors (hopefully)
wsadmin -lang jython -f deployConsole.py install
Admin console should work now.
I had a similar problem. I was able to solve it by:
Deleting the existing profile
Creating a new profile
Running the WAS in RAD with that newly created profile
Profile management :-
Method :- RAD -> windows > prefereneces > server > websphere application server > selecting the websphere server 7.0 > click the run profile management tool button in the bottom section.
Check and make sure the DMGR is up and running on the primary node. Start --> Run --> Services.msc. Look for something that looks like "IBM WebSphere Application Server V6.1 - CellManager01" and ensure it is running. If not, browse to the installation location of Websphere "AppServer\profiles\Dmgr01\logs\dmgr" and look in the Systemout.log and the SystemErr.log for details. Also look in the "AppServer\profiles\Dmgr01\logs\ffdc" directory.
You can try this before trying to delete the new profile. I had this same problem where console was not coming up. I closed the RAD and re-opened it but didnt work. Go to Window --> Reset Perspective and then go to show view and get the console.
If still you cant see the console, go to customize perspective and click general and enable console.
If this doesnt work then only delete and recreate profile.

debugging java application deployed in tomcat

I have an application that I deployed in tomcat. Later I configured the code as a project in Eclipse. I want to connect to the tomcat via eclipse and debug the application.
Trying to setup a remote debug connection is throwing up errors. Is there any entry that I need to add somewhere in tomcat?
First, you need to run Tomcat in debugging mode. The easiest way to do that is to modify the startup file (.bat or .sh depending if you are Windows or not). Find the line near or at the end of the file that contains the start command, and change it to jpda start. This will cause Tomcat to start in debugging mode listening on port 8000.
Next, to connect to this process via Eclipse, select the Run menu and choose Debug Configurations.... In the pane on the left, choose Remote Java Application and click the New launch configuration button above the list. The important settings to note are the Host and Port fields. The host value must match the hostname of the Tomcat process, and the port should be 8000. You also might need to add entries on the Source tab to ensure that all of the source code is available to step through.
Create a new tomcat server
Create a new dynamic web project
Export war to tomcat server
Tomcat debug configuration(important), first double click tomcat server, then select "Use Tomcat installation (takes control of Tomcat installation)"
Add breakpoints
Run tomcat in debug mode
Test war in web browser
Edit source path
Debug source code in Tomcat
The war file is available here.
yes, you need to configure tomcat to accept remote debugging connections. There is a FAQ on how to do it with various IDEs.
http://wiki.apache.org/tomcat/FAQ/Developing#Q2
Simply change the line in startup.bat (if you are using Windows)
from:
call "%EXECUTABLE%" start %CMD_LINE_ARGS%
to:
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
Right Click on the project you want to debug and go to Debug As Menu and in the list click on Debug Configurations.
Then Double click on the Remote Java Application from left menu list. browse for the project u wanna add in then click apply.
Also change the listening port to 7999, then after you started the web app from your localhost click the debug button on the same window. Then any break point's will be hit after that.
Steps to setup the tomcat Debugger with eclipse
Install the following things:
java 1.8+
eclipse EE version
download tomcat 8+
open eclipse and go to servers tab and add a new server(window-> show View-> Others -> Search Servers)
Mark your project as Dynamic web Project(Rightclick on Project-> project facets -> select Dynamic web module)
Export war (File-> Export-> search war -> select module and choose the path)
Run as -> Run on Server
Start the tomcat Server in Debug or Run Mode
check on localhost:8080
Debug worked for me. I was using tomcat 8, configured on centos 7. Debug port opened for me after changing 2 settings.
Open tomcat/conf/bin/startup.sh and added below lines
export JPDA_ADDRESS=8000
export JPDA_TRANSPORT=dt_socket
In the same file startup.sh, added jpda before start command.
exec "$PRGDIR"/"$EXECUTABLE" jpda start "$#"
Restart the tomcat.
In eclipse go to Run>Debug configuration>Remote java application>Add host ip and port(8000) where tomcat is running.
In my case i required to open 8000 through firewall too.
firewall-cmd --zone=public --permanent --add-port=8000/tcp
firewall-cmd --reload
Beside remote debugging, you can debug your app locally within eclipse if you added tomcat in eclipse.
just start server and wright click your app and from debug menu hit debug on server.
If you have multi module maven project, debug on server just shown up for module with war packaging.
If you want debug a class that runs at startup by self, like methods that annotated with #PostConstruct, remember that you should increase server timeout.
To do that, go to server view and double click on tomcat and in server preview tab, increase the timeout value.

Attach debugger to application using Eclipse

Can you attach to a running application using Eclipse, similar to how you attach using Visual Studio?
Yes.
If you start your server with the debug port open, by adding this into your java command:
-Xdebug -Xrunjdwp:transport=dt_socket,address=127.0.0.1:8888,server=y,suspend=n
And you have the source code in your project (technically this isn't required, but it's kind of useless unless you do), you can connect to the running server by setting up a "debug configuration"
with host = the machine the server is running on and port = 8888 (for example - see options above)
You can then set break points and the debug session will halt the server there and you can inspect variables/fields, and even set their values.
Update
The more modern command-line options for the JVM to do this are
-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:8888,server=y,suspend=n
The Debug Configurations panel has a menu item Remote Java Application:
How about just do this:
"Open the DDMS perspective, select the device and attach to your app's process (you will see the package name listed)"
.. thanks to this post: https://stackoverflow.com/a/10074263/2162226

Getting 'shmemBase_attach failed: The system cannot find the file specified' when trying to attach to applet to debug

I'm using netbeans 6.1.
I've got the following in my java run time settings:
-agentlib:jdwp=transport=dt_shmem,address=jdbconn,server=y,suspend=n
and the following in the attach dialog in netbeans:
Debugger: JPDA Debugger
Connector: Shared Memory Attach (Attaches by shared memory to other VMs)
Transport: dt_shmem
Name: jdbconn
I got the above settings from the FaqDebuggingAppletRemotely page on the netbeans Wiki.
The applet is in an aspx page (the applet, whcih is signed, is a method of communicating via the client browser to a legacy platform, I'm a C# developer really). I've managed to get the security warning to display which gives me a chance to attach to the applet but whenever I try to attach I see:
Attaching to jdbconn
shmemBase_attach failed: The system cannot find the file specified
in the output window in netbeans.
Any help gratefully received!
I would bet anything (almost anything ... maybe a few dollars at least, or a cookie) that the JVM installation your applets are running on is NOT the same as the default JVM installation that is installed on your system.
To find the JVM installation that your browser and applets are using in Windows 7:
1) Close all applications that use the JVM (especially the browser).
2) Open the windows task manager (CTRL+ALT+DELETE->Task Manager), and click on the processes tab.
3) Make sure there are not any java*.exe processes running.
4) Open your browser and go to the applets page, and start the applet up again.
5) Now go back to the Task Manager->Processes tab and look for the java*.exe that is now running (it will most likely be "java.exe *32" literally, as in it will literally have an asteriks in the name of the process. If you don't see that one, then just use whichever one IS running).
6) Right click on that process, and in the context menu select "Open File Location". This should bring you to the "bin" folder location of the installed JVM that your browser is using to run your applets! Are you surprised that it is not the same as what you thought it would be?
To find the task on linux or other systems:
I've only ever had this problem on Windows, but here's how you do it anyhow.
Open a shell, and type the following
ps -e | grep java
And make a note of the pid(s).
Now that you know which JVM your applets are using:
We need to open the Java Console for that partivular installation (as opposed to the default installation we tried to modify before).
To open the Console of the JVM installation that your applets are using, and set the runtime parameters:
1)Open a command prompt (shell or whatever) in the bin folder of the JVM installation. (In windows 7, from the explorer, you can shift+right-click on the bin folder, and select "Open Command Prompt Here").
2) Run the following command to open the console:
javaws -viewer
This also ends up opening the "Java Cache Viewer" window, which we do not need. Close that window, but keep the "Java Control Panel" window open.
3) You can now go to the Java tab, click on view, and modify the runtime parameters just as you did before:
-agentlib:jdwp=transport=dt_shmem,address=jdbconn,server=y,suspend=n
4) Click "OK", and then click "Apply" in the main java console window to apply and save all the changes you made.
5) WAIT! There is one last thing that I suggest you do; clear out the java WebStart cache to make sure your applets download fresh using the new parameters:
javaws -uninstall
Be sure and run this in the bin directory of the JVM installation that your applets are using, since this might not be the same bin directory that is pointed to by your Path (or PATH) system environment variable.
Now start up your applet from your browser, and create another shared memory connection inside your NetBeans IDE! Setup break points in the correct source code you are debugging ("source" tab in NetBeans), and start using your applet. You should now see that Netbeans is breaking on your break points!
At least, I hope so...
When you debug with the shared memory option (transport=dt_shmem), you're using Windows internal shared memory objects to communicate between the debugger and the jvm.
This means that if you're:
a. Not debugging from the same physical machine as your jvm, or
b. Not working on a Windows OS,
You can not debug in this mode.
I'm not sure what would happen if you ran a Window on a VM on a Linux station...Might work and might not.
If both of the above are fine, it would require a deeper investigation to find out the problem, but in the mean time, you could attach with a plain socket.
In the Java run time parameters specify:
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=y
This tells your jvm to run in debug mode, load the jdwp library, wait for connection to attach in port 8000, and suspend execution until such a connection arrives.
In your IDE set the remote debugger accordingly. I don't know Netbeans, but it would be something like Connector = socket connector, address=8000.
When you start your web page, the applet will freeze loading until you connect, and of course you can't connect until it has reached the listening stage.
Good luck!

Categories