简体   繁体   中英

Proper way to configure IntelliJ to use source code for decompiled jar

I have been trying to figure this one out for a bit, not coming up with the right approach. I read through this question , which I'd already tried, but it's not working quite right.. using IntelliJ EAP 142.4675.3

What I am trying to do, is to debug a junit test using a jar (extending the Provider class) file I've placed into JAVA_HOME\\jre\\lib\\ext. I want that jar to be debuggable as well.

The problem is, if I attach my source directory as the source for a jar, then, in a stack trace, when I click the named file (containing a method I wish to view), IntelliJ asks me to choose between two of the same file, presumably because it knows about the source (it's in a module in my project) and it's also been told about the source via the jar source path I added.

I tried adding the provider.jar to the project module dependencies tab, which caused intellij no end of grief. Reverted back to having it in jre\\lib\\ext, and, in the Platform Settings->SDKs->1.8->Sourcepath tab, I added the module sourcepath. This lets intellij step into the .java file for the jar, vs the .class file, but, when it does so, I now get a banner at the top of my code windows which says "Alternative source available for the class xxx" and there's a combobox at the RHS with the module name listed twice (in the latest EAP, it actually lists the module and the jar [same name as module, with .jar]). And, as mentioned earlier, the IDE asks which which (of the very same) file I wish to edit when I click a file in the stack trace.

Clearly, there is something not quite right.. what am I missing? I find it odd that the ide will not open the source code when stepping into the jar until I attach the code as above, but, when I do, it sees it twice.

So let's start from scratch:

  • File > New Project, choose "Java Module", fill the form: 捕获器
  • Bypass the form asking about the kind of project (webapp etc) by clicking on "finish"
  • you now have a project with a src dir: 捕捉2
  • right click the 32910506 directory and choose "New" then "Directory" and create a new directory named lib.
  • drag and drop your 2 jars (sources and code) to this directory (I will use common-lang for this example), beware to copy, not move: capture3
  • now right click on src , choose "New", "Java class", name it App : capture4
  • right click your "code jar" and choose "Add as library": capture5
  • in App type psvm then hit TAB to get a main and fill it like this: capture6
  • right click on your "code jar" and choose "Open library settings": capture7
  • click "+" and choose "Attach file or directory" and select your "sources jar": capture8
  • Now if your Ctrl +click on random in App, you should end up to the method source: capture9
  • Put a break point in the random method:

capture10

  • Now right click App , choose "Debug App.main()", you should end up to the previous breakpoint: capture11 capture12

Used: idea 12.1.6 under linux

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM