How to include NetBeans Platform Source code into module dependencies - java

I am debugging a NetBeans Platform application.
I have downloaded the NetBeans Platform source code .zip file.
I would really really like to attach the source code to the debugger so that I can seamlessly jump to internal NB source code.
Normally I would edit the Library configuration to tell NB where to find the source code, and it would just work.
However this is not possible for NetBeans Modules; when I look at the Utilities API module dependency it does not look like a normal NB library and there is nowhere to add in the source code.
I suspect that if I were to rebuild my project using Maven this would work automatically.
But thats a terrible reason to switch to maven.
How can I get the NB Platform Source code included into my Module Dependencies ?

You can add the zip to the 'Source' window.
To open the Sources window
Select the 'Debugging->Sources' item
from the Windows menu
To add the zip file to the sources...
right click somewhere in the window.
select 'Add Source Root' from the menu that appears
alt text http://www.freeimagehosting.net/uploads/87c4e3fc8c.png

Related

IDEA decompile instead of download source code from maven when click into source code

In Eclipse, when ctrl + left click into a type of 3rd party library from maven repository, it will download the source code jar automatically, then show the source code of that type.
But, it seems IDEA (2018 version) simply decompile the .class files, and show the result, without downloading the source code.
The question is:
How to let IDEA download source code jar file from maven, and show the actual source code, when click into a type? (Just like what Eclipse does.)
IntelliJ IDEA has an option to download the sources automatically:
If you enable it in the existing project, you will need to Reimport in the Maven tool window to get the sources downloaded, or use the button to forcibly download the sources:
Yet another option is to Download sources or specify the sources location manually via the panel at the top of the decompiled file in the editor:

Eclipse console hyperlink only can jump to Java class file in referenced libraries

I need create hyperlink in eclipse console to link File name on the console to java source file. However, Eclipse only can jump to Java class file in the "referenced libraries" but cannot jump to Java source files.
My project is a Maven project. Any idea to make Eclipse console search files in source code folder instead of only search on the "referenced libraries" ?
My Eclipse is Spring IDE 3.8.4 which is based on the Eclipse Neon.3.
Below figure is OK case, FrameworkServlet.java:489 is a class in referenced libraries.
However if file is a Java source file in src/main/java then Eclipse cannot jump to that file (FileUtils.java)
Thanks.
You simply need to ensure that your source folder is on the build path. Go to your project properties, click Java Build Path in the left pane, click the Source tab in the right pane. If your source folder is not present, add it. Eclipse should be able to find your source file after you do this.
Besides what D.B. mentioned, make sure the source folders is high in the Order and Export tab so that Eclipse would look for current project's source class first.

Eclipse & Spigot - Trouble attaching source

I've been trying to find a way to attach source into eclipse. I built the spigot.jarand decompiled it into a zip file using JD. Here is the file if you want to take a look at the zip. Now what I'm having trouble doing is attaching the source to a project in eclipse. Yes, I of course have it in my build tools,
but I want to inspect some class' to see if I am using sockets/packets correctly. Here is the picture that eclipse gave me. I've already attached the source to that zip, but it wont work.
Any ideas?
You need to add the built jar file the buildpath of your project. In eclipse just right-click your project, click on "Properties", select "Java Build Path", select the tab Libraries and click on the button "Add External Jar" on the right side. Then choose the Bukkit/Spigot jar file you want to work with and build against on export.
If you need a detailed video tutorial on it:
https://www.youtube.com/watch?v=7dyopdta7ZI

IntelliJ - How to jump to source instead of compiled classes from failed unit tests in the "Run" view

When I run my JUnit tests in IntelliJ and one of them fails, I would like to jump to the source code of the failing test by double-clicking it (or by right-clicking it and selecting "Jump to source" or "Show source") in the results view (in the list of failed tests in the "Run" view). However, this feature doesn't always work correctly. Sometimes the source code is shown and sometimes only the compiled ".class" file of the test is shown to me in the editor window.
I would always like to see the source code (".java" file) instead of the ".class" file in the editor window after double-clicking the failed test.
One solution for it is to click "Attach Sources..." in the editor window, where the ".class" file of the test class is displayed. However, I have to do it for every test file and it takes much time to do it repeatedly for every test. In my opinion IntelliJ should find the source code automatically, because it's present in my Project (it's my own class and its source code is in the project and I run this test from the Project view, where the classes with source code are visible). How can I configure IntelliJ, so that it finds the source code automatically for every unit test which I run?
The ".class" files which are shown instead of the ".java" files are contained in a jar file which is built by Maven.
You should be able to go to the External Libraries in your Project view (File > Project Structure), find the jar that contains the .class file, and right click (or F4). You will see Open Library Settings. From that dialog, you can attach a src folder to the library.
I'm using IntelliJ IDEA 2019.3 ultimate edition and faced this issue, debugger would jump to decompiled .class files
On the top right corner once your debugger jumps to .class file
you will see an option to 'choose sources', choose the directory which has your .java file. Worked for me atleast.
I had a similar issue. In my case it was due to incorrect Module configuration. Basically you must ensure that the source folder containing the java files is added to Sources tab in corresponding module.
To do this Go to Project Structure (Ctrl + Alt + Shift + S) and select Modules. Choose corresponding module and verify that the source folder containing the java files is correctly added to the Sources Folders. If it is not then add it.
I got this issue today. The solution for me was to right click on main pom.xml, then maven, then reimport.
I Had a similar issue. The issue was still there even after pointing to the correct source folder but I got rid of it by setting the classes folder to the source code's root folder.
Add a solution to JAVA Maven project.
Open 'Libraries' from 'Project settings', search and select the Java jar you want to attach source file. Then you can add source directory by click the '+' button.
I Had a similar issue. The solution for me was to close project, delete .idea folder than re open the project.

Opening source code from debug view edits .class after Android R18 update

When I'm debugging my code in Eclipse, I get annoyed when I open up the editor to find out I cant edit it because I'm actually viewing the source of the .class file. How do I get Eclipse to open up the .java file instead of the .class file when in debug mode?
EDIT: When I hit a breakpoint in my code, it brings me to MyFile.class, instead of MyFile.java, so I can see my code but not edit it.
EDIT: I'm guessing it has somethign to do with Android and ADT R18
After I finally found some time and good reason to look into this issue a bit deeper I'll elaborate a bit on Thornbjorn's answer.
As of lately, Google changed the way your Android projects package your external Android libraries. In ADT R17 (I think) it started packaging the external projects source into .jar files and including them directly into your project in the Android Dependencies or /libs folder.
Now, when the debugger hits a breakpoint, it brings up your source code in the .jar, essentially telling you to edit a .class file. The problem is that this file is read-only and so you have to go find your .java source manually. (Pain)
The fix is to right click the Project name in the debug view, and select "Edit Source Lookup..." from the menu. From there, remove the Default lookup path. After that, manually add the associated projects (not jars) that your project references. This is done by clicking Add, selecting Java Project, then checking the appropriate projects.
OK, so I hate to be "that guy", given the number of people for whom this worked, but this didn't work at all for me. I mean that the "Edit Source Lookup..." menu item was not in the context menu. I did not miss the instruction to do this in the Debug Perspective (presumably in the Project Explorer in the Debug Perspective). I tried it while the app was running and while the app was suspended. I tried checking the menu for the application's project (presumably what the instructions refer to) and for the library's project. No dice. This is with the latest Eclipse build.
However, I was able to resolve the issue:
Set a breakpoint in either your application or the library you are trying to link source for. You can actually put this anywhere as long as the library you are trying to link source for has a function that will appear on the call stack when the breakpoint is hit.
Start debugging your application.
Navigate your app to hit the breakpoint.
Make sure you are in the Debug perspective.
In the Debug tab (where the call-stack appears), find any function from your library.
Right-click that function. The "Edit Source Lookup..." menu option should be there (close to the bottom).
From here, the instructions are the same as Styler's. Click "Add", select "Java Project" and add your project (or multiple projects).
Before you exit the "Edit Source Lookup..." window, if you are like me, you will see that Eclipse has chosen to add a bunch of stuff to the list that you didn't choose. Some of that stuff (probably under expandable items with names like "Android Private Libraries" may be the jars for the libraries you just added source for. Remove those jars from the list.
Profit!
Open main project properties -> Java Build Path -> Projects tab and add there projects the main project depend on.
Switch to Order and Export tab and uncheck Android Dependencies
Enjoy
For some reason Eclipse does not believe that the class file comes from your Java file. This is frequently a malconfigured buildpath, or a jar-file used instead of the project generating the jar file.
Look in the project manager panel (<->button) to see where Eclipse finds the class file and then figure out why it uses that location instead of your project with the source file.

Categories