25

Please let me know how I can debug any jar file with source code attached in eclipse.

When I tried to debug it, implementation is completed as desired but control never reached the breakpoints.

7 Answers 7

25
  • Right-click on the jar referenced in your project, select 'properties'
  • From 'Java Source Attachment' click 'Workspace...' button
  • Select the 'src' folder from the jar project in your workspace

or if you want to do more steps:

  • Right-click on project, select 'properties'
  • From 'Jave Build Path' select 'Libraries' tab
  • Expand (click '+') the jar you want to link source to
  • Click 'Source attachment' (it should be saying 'Source attachment: (None)')
  • Press the 'Edit...' button
  • Follow from the second point in the shorter steps above
Sign up to request clarification or add additional context in comments.

Comments

14

Use below command to launch your jar:

java -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y -jar [JAR NAME]

It should state something like :

Listening for transport dt_socket at address : 8000

In eclipse, create a "Remote Java Application" debug configuration and add the modules of jar.

Comments

10

You try this one:

First open the jar file using JD(Java Decompiler), then click on File -> Save JAR Sources and it will become a .zip file containing the java source files. Then you can add this source zip file in the debug configuration using add source. It will work then for sure.

I also faced the similar issue,sometime while debugging the jar file classes. But after the above procedure the issue got resolved.

Comments

2

i have done this many times and it works fine for me. Make sure you have put the debug points at right position. May be because of some condition code will become unreachable at that time debug point will not take effect. Place debug point at calling statement of method means where you have called the method of jar class. If control reaches there then press F5 to enter to the method in class of jar file. If control does not reach there that means you have some conditions in code which prevents calling that method and thus you can not get to your break point in method.

2 Comments

I have inserted one print statement there and it got printed on console but the breakpoint doesn't get hit at same statement.
@Kaveesh Wadhwa : Clean your workspace. 1)Stop your server. 2)Go to Project-->Clean... option. 3)Select clean all projects 4)Press ok. 5)Restart your server. By doing so do you see a right mark under the debug break point when the server is on?
2

You got this page, if you don't have source file.. enter image description here

Click "Attach source" button, you got this page..

enter image description here

If you have source code in your workspace, you can directly select by this way..

enter image description here

If you have source code in external location, select external folder and select src of your source code..

enter image description here

If you added source correctly, you can debug those files..

Comments

0

"The workaround is to go to PDE 'Target Platform' preference page and disable all the external plug-ins. They are causing the problem because the model synchronizer that should prevent the appearance of 'twins' is not working properly."

Reference link - https://bugs.eclipse.org/bugs/show_bug.cgi?id=22961 Comment #10.

The above workaround worked well for me.

Comments

-1

Using Eclipse version Oxygen.2 (2017), the following procedure was successful for me.

  1. Launch the application to debug with the Xdebug and Xrunjdwp switches.

    cd "C:\Program Files\Test_742\Test 7.4" test_app.exe -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8500

  2. Create a new workspace in Eclipse.

  3. Create a new Java project using File -> New -> Java Project.

  4. Copy the source code of the Jar to debug to the src folder of the new project. I found it necessary to ensure that I copied the complete folder hierarchy of the source code to my source folder.

    For me that meant copying \com\test... to my src folder.

    This puts all the source code in the build path.

  5. Copy any dependency JARs to the project. I created a new folder named myJARs.

  6. Refresh Package Explorer to see the new myJARs folder.

  7. Add the dependency JARs to the build path by opening File -> Properties -> Java Build Path -> Libraries (tab), and click Add JARs...

    Add each dependency JAR to the list, then click Apply and Close. This adds the JARs to Referenced Libraries.

  8. Configure a debug session. Click Run -> Debug Configurations -> Remote Java Application. I set Connection Type = Standard.

    Configure Host to point to the machine running the JAR and Port to the port specified in the address portion of the command line switches (8500 in my example).

  9. Notice that on the Source tab, both the source files and the dependency JARs are present.

  10. Click Apply, then Debug.

  11. View the debugging perspective by clicking Window -> Perspective -> Open Perspective -> Debug.

  12. Place breakpoints in the source code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.