I have a jar file which is having some issue and I would like to debug it.
I created the application on eclipse. During dev phase I have done debug but with the source code. I wanted to debug jar file to find out the reason of error i.e. it could be source code I have is different from jar file or some jar file issue.
Seems like you want to remote debug.
The use this command to launch your jar:
java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y -jar [JAR NAME HERE]
It should state something like :
Listening for transport dt_socket at address : 8001
And in eclipse, create a "Remote Java Application" debug configuration. The configuration is the only thing that matters as long as you have your project of interest open. Add the project[s] of interest that you would like to debug onto your source lookup path and set the port number to the configured address from the java launch command.
When you connect to your debug-enabled jar launch, your jar will halt execution and await debugger input upon hitting breakpoints. Just make sure you have the same version of the code in your jar and your eclipse.
You can use a java decompiler to that effect. I suggest jd (http://jd.benow.ca/).
However, you would also need to include a realign feature (http://mchr3k.github.io/jdeclipse-realign/) for the line numbers to match.
Of course, this can only work if debug information is included in the jar file.
Related
I have a remote server that is running a Java program in debug mode.
It has the following Java opts:
JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"
I can successfully connect to it with an IntelliJ Debugger.
I can stop the process from IntelliJ and also get thread dumps.
I would now like to add a breakpoint for a certain method. However, using the Breakpoint window to set i.e. a wildcard match for class pattern and a method name works theoretically, but it is so extremely slow that it’s impossible to use it to debug web requests.
I do have the jar available so I would like IntelliJ to decompile the jar, show it to me as source code and allow me to set breakpoints in the decompiled jar.
How can I achieve this?
(I have full permissions to do this and also the actual source code available, but for legal reasons I cannot transfer the source code to the machine from where I‘m debugging)
Turned out to be fairly simple:
Open the folder with all the jars in IntelliJ (they show as a list but aren’t „browsable“
Right-click the folder, „Open Module Settings“
Go to „Libraries“
Click „+“ and then „Java“
Select all the jars in that directory
Now all the jars are browsable
Set breakpoints in the jar code
Im using the following config the debug jar file that under my root project, when I click on debug the program start to run but doesnt stopes since I didn't set any break-point(as this is jar file :) ) , In node.js there is option to do it with --inspect-brk info which stops on the first statement but not sure How to do it on jar file
My questions are
How can I stops in the first line of the program jar ?
Does my config are OK?
Oterwise , how can you able to debug jar if you cannot set a break-point ...
EDIT:
I've tried with the suggestion of crazycoder and it's not working, any idea?
What I tried is to create under my root project decomplie folder and run the following command
java -jar fernflower.jar zte.jar + decomplie/
I got erorr of course of not found
I've also tried with
java -cp java-decompiler.jar org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler zte.jar + decomplie/
Could not find or load main class
org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler
How to I get this jar (fernflower.jar ) or the path to it ?
EDIT2
My project is like this
-myjavaproj
--zte.jar
--decomile
---zte.jar
---com.proj.cli
----appmain.java
For your specific project that is one jar file (zte.jar) which contains deps.zip inside which in turn contains other .jar dependencies and no sources at all and also uses reflection and custom classloader in order to load and use the .jar files in deps.zip; for the debugger to work, you have to unpack all the jars from the deps.zip into some location, then make a new IntelliJ IDEA project and add all the jars (including the root zte.jar and all the jars unpacked from deps.zip) into the module dependencies.
Browse to CliExecutor inside the self.jar, in the project view, IntelliJ IDEA will decompile it, place the breakpoints, debug it.
Your config is a little strange, but correct. The VM options you provide tell the JVM to wait with running the zte.jar until a debugger is attached.
So you won't automatically stop on the first line, you need to add break-points in IDEA and attach it manually to the JVM process. This is explained here How to remote debug JVM
Keep in mind you are doing one thing sort of wrong. You do not need to setup the debug options in the VM options. Just select the JAR you want to debug, place break-points and start in debug mode (that is the bug like icon in IDEA).
For some reason I can't get JRebel work on external Tomcat 7 with Eclipse. Everything works fine if I use server runtime in IDE, but if I launch server from command line and deploy application externally, JRebel doesn't reflect my changes to server.
Here is how I configured and deployed my project:
Enabled JRebel on project from projects configuration tab
Startup set to Run locally from command line
Created catalina-jrebel.bat according to generated configuration
Built project using maven
launched server using catalina-jrebel.bat run
Deployed war file on server from Tomcat's application manager
Now, if I modify my sample Servlet and save, nothing happens. Application behavior doesn't change, nothing in console.
Am I missing something, and how to debug the problem?
Here is the content of catalina-jrebel.bat
#echo off
set REBEL_BASE=C:\Users\tutoivon\.jrebel
set JAVA_OPTS="-javaagent:C:\SLO\eclipse\plugins\org.zeroturnaround.eclipse.embedder_6.4.4.RELEASE\jrebel\jrebel.jar" %JAVA_OPTS%
call "%~dp0\catalina.bat" %*
Some things you can check by yourself:
Server starts up with JRebel banner - so you can be sure JRebel Agent was actually attached to server.
In the banner it says that you have valid license - no license, no reloading.
The built .war contains a rebel.xml inside WEB-INF/classes - this helps JRebel to find the location of classes updated by IDE.
The paths in rebel.xml are absolute and correct, no placeholders (e.g. ${rebel.workspace.path}) are used - if placeholders are used, then they must be defined by passing e.g. -Drebel.workspace.path=/path/to/workspace to JAVA_OPTS. If done correctly, JRebel will also log a line such as JRebel: Monitoring directory '/path/in/rebelxml' in server log.
If you still can't get it to work after these steps, contact support#zeroturnaround.com.
I'm attempting to run a Java/Spring/Hibernate/ application using IntelliJ 13 and its built in Tomcat deployment plugin. When debugging a buddy of mine has the following logs.
I was wondering how to enable the logs that are in red, currently in my IDEA. I have tried the following solution.
Heading over to the Run/Debug Configurations Tomcat server and clicking on the log tab and enabling the logs
I appreciate any help or tips in advance. Thanks guys
If I am understanding your question correctly, you are not sure what to set in the "Log File Location" field of the "Edit Log File Aliases" dialog.
When you create a Tomcat Run/Debug configuration, IntelliJ IDEA creates a TOMCAT_BASE directory as {intellij_system_directory}\tomcat\{run_configuration_name}_{project_name}. (TOMCAT_HOME identifies where the binary files are and TOMCAT_BASE defines where an instance of tomcat is. Sometimes they are the same. In this case, they are not.) The {intellij_system_directory} directory is usually in ~/.IntelliJIdea13/system where ~ is your home directory (C:\Users\{username} on windows). See the document Directories used by the IDE to store settings, caches, plugins and logs. You can also go to Help > Show Log File which will pen the directory {intellij_system_directory}\logs. Just go up one directory and then into tomcat.
Just set the path to the appropriate logs directory. You can use ant file patterns to deal with dates. For example, for my Tomcat Run\Debug configuration named "My Web App" in "My Project", to view the catalina.log file, I would set the path to C:\Users\Mark\.IntelliJIdea13\system\tomcat\My_Web_App_My_Project\logs\catalina.*.log. The * wild characters the date stamp in the log name and IDEA will always open the latest/newest one.
Also take a look at this post -- https://devnet.jetbrains.com/message/5529312#5529315 -- of mine for information on a minor bug with naming of the tomcat base directories.
Given a remote JNLP which works (all jars are available etc) but you need to run a debug session on the code.
Is there any facility that easily allows you to create a local project in ANY reasonably modern IDE which consists of a local copy of the resources stated in the JNLP and can run said code in debug mode? Assume that a decompiler is available so it is just a matter of getting the debug session running.
Are there any IDE's (Eclipse, Netbeans, IntelliJ, JDeveloper, etc. etc. - even a commercial offering) which can do this just given the JNLP URL?
I have a pre-defined project in Eclipse which is blank except for a utility that parses a JNLP file and downloads all the jars specified in the jnlp codebase. Optionally, you can replace any jars with updated code you want to test here. It uses reflection to add all the jars to the classpath (which is a hack) and then reflectivly invokes the main method of the class specified as the main-class in the JNLP with any arguments.
Unfortunately I can't share the source for this but it only took me a day to get it running.
The class path hack is available here: How should I load Jars dynamically at runtime?
Should work well with any debugging.
I am facing a similar problem with a JNLP program. The only way I found to debug the program is by debugging into Eclipse (I have the project and the code source) and copy-pasting all parameters passed by the JNLP file in the Arguments tab into Debug configuration in Eclipse. I don't know if this is related because my problem came from the arguments passed to the application through JNLP file.
I don't understand something... Why you want to debug directly on the compiled code from the final location?