Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I link source to a jar package in eclipse?

How can I link source to a jar package in eclipse?

I am trying to add the external library ch.ntb.usb.

I added the jar file to my build path, but when I tried to run the application it returned the following error:

The jar file ch.ntb.usb has no source attachment.

I've used JD-GUI to decompile the jar file and the source code is contained.

like image 602
Sean Greevers Avatar asked Dec 10 '11 05:12

Sean Greevers


2 Answers

I doubt that you get that error when you only run the project unless you have an error in your code and eclipse debugger try to show the line of code that cause the exception, anyway you may need source files of a library for debugging purpose, to link source to a jar package in eclipse you can follow these simple steps :

  • Find the package which you want to add the source under Referenced Libraries in Package Explorer
  • Right Click on the library
  • Select Properties
  • Go under Java Source Attachment
  • Select the directory or archive where your source is located.

example

like image 141
aleroot Avatar answered Sep 17 '22 12:09

aleroot


I "Saved all sources" with jd-gui into my build path as ch.ntb.usb.src after unzipping the jar file. Then I set the source attachment of the external library to ch.ntb.usb.src. This fixed the issue.

like image 29
Sean Greevers Avatar answered Sep 21 '22 12:09

Sean Greevers