Intellij IDEA Breakpoints stop in JARs instead of source code of my project - debugging

I set a breakpoint in my .java file. I started jetty via maven-jetty plugin. The java file where I set the breakpoint is also packaged into a JAR.
Intellij stops at the breakpoint, but it shows me the file which is packaged into the JAR instead of the java file. It behaves as if I set a breakpoint in a java file of 3rd party libraries source code.
How can I either make Intellij ignore my JAR or force Intellij to stop at my .java file?

In the current latest version of IntelliJ IDEA (2018.1) there is an option "Show alternative source switcher":
After enabling this option IDEA detects discrepancy of *.java and *.class files and offers to choose source of sources (sorry about tautology). It can ease pain of debugging in projects that consist of many modules.

The setup for this is two fold.
Add the source to one of your modules' classpath. (Project Structure -> Dependencies -> Add -> Module Dependency -> Pick your source and drag it above all library dependencies)
Point your Remote Configuration to search for the sources in that particular module's classpath. See picture below
There is an option to search "whole project" for sources, but this did not set precedence to locally available sources, over downloaded sources, when I attempted to use it. The above solution fixed this problem for me, but it is relatively unsatisfactory when working with a large multiple project setup. i.e I had to pick one particular module's classpath as the source of truth in Remote Configurations. In my opinion, if the local source is present, and "whole project" is the search option, IntelliJ should be smart enough to choose local source over libaries

Related

Netbeans can't find sources in non-standard maven project layout

I'm trying to use Netbeans 8.1 to work on a Maven project with a non-standard project structure. In my project, my sources are under src/foo instead of src/main/java. To open my project, I click File > Open Project... in the menu. Then I navigate to my project in the file browser that opens. Then I select my project and click Open. When my project opens in the Netbeans Projects tab, it does not contain any source packages. It only shows a folder labeled Dependencies and a folder labeled Project Files.
I've tried changing the location of the source folder in the project properties to fix this. I right-click on the project, click Properties, and then click Sources in the menu on the left. Then I try to edit the Source Folder value, but the value isn't editable. It's worth noting that for ant projects, I can add sources in the project properties, but for Maven this doesn't seem possible.
Does your maven project actually build correctly? The IDE will pull the source location from your POM model. Eg.
<project>
<build>
<sourceDirectory>${project.basedir}/src/foo</sourceDirectory>
</build>
One solution is to change your project so that it uses Maven's standard directory layout. One very easy way to do that (if you have your sources under one directory), is to create symbolic link from src/main/java to src/foo:
mkdir src/main && ln -s /path/to/project/src/foo src/main/java
If you do that, Netbeans will be able to see your sources, and you can keep your non-standard directory structure.
Possible Alternative: When searching for alternative solutions to this issue, I found that I could import the project into Netbeans as either a Java Project with Existing Sources or a Java Free-Form Project (I'm not sure which one I used). However, Netbeans won't let me do that anymore, so I'm not sure if it will always work and I'm not sure of the steps I took. If you want to try that solution, click File > New Project, choose the Java category, and choose either Java Project with Existing Sources or Java Free-Form Project. In the next window, point Netbeans to your existing sources as the location of the project. As I said above, I'm sure that this worked for me once, but I cannot use this method anymore as Netbeans shows the following error:
Project folder is managed by a project foo-project-name. Instead of creating a new project just open it. If by a chance you just deleted the project foo-project-name than [sic] restart the IDE to reuse the folder.

Can't navigate to sources for Maven dependencies easily with IntelliJ IDEA 12

I added a library to maven by searching from within IntelliJ, and I checked the boxes to download sources and javadoc, which Idea tells me it did.
However, in some of the library files I click into, it just says "/* compiled code */", even though the exact source code for those files is available in another jar which i can see right there in the project.
Does anyone know how to fix this?
If you check the libraries tab in the project settings you'll see that each library can have an entry for its sources jar. If the one you're looking for doesn't have one, add it manually.
This is all a lot easier if you use maven.

Why don't GWT launch configurations lookup sources in dependency projects by default?

Why there's a difference in Default Source Lookup Path between GWT and java launch configurations?
In multi-module projects instead of containing projects, the Default folder contains the class folders of those projects!
It causes "Source not found" errors when the debugger steps into a dependency project.
I know I can add projects manually. Just want to know why this difference is needed.
The only project in the list is the associated with the .launch.
GWT needs '.java' source files of dependencies to be able to compile (translate to js) while the Java launcher needs only '.class' compiled files.
I suppose you know GWT has a different way to manage dependencies (through modules within the same project), which is good for some advanced GWT practices like loading a module's js lazily (this feature doesn't work with "foreign" libs/projects).
So this could also be an answer for why eclipse GWT doesn't suppose you will have more projects (but more modules instead)
Finally if you really have an independent GWT lib that you're maintaining this is an issue as you said.

Eclipse Plugin project: manage external files

I'm developing a plugin for Eclipse (4.2 on windows) that uses a bunch of external files (batch scripts, xml files, ecc).
I'm asking if there is a good method to manage those files inside the project in order to:
keep all the plugin resources inside the project for version control in SVN
possibly have an automated plugin installation (including those files outside the plugin jar)
Edit: Can an additional "Feature Project" be a solution?
Instead of having a project I would manage two: one for the plugin and one for the "feature" that references the plugin and gathers the non-plugin data.
In that case, I see that eclipse "Features" have an "installation" section (in "feature.xml"). How could I specify for each "non-plugin" file the install path location?
I'm using nested projects for this.
Create a parent project that will contain everything. For each sub-project, deactivate the default location when you create it and select the parent project's root folder instead.
Here is an example: http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/tree/
It doesn't have a .project file in the root but having one doesn't hurt.
Just remember to import the sub-projects before you start working on them. Otherwise, you and Eclipse might get confused.

IntelliJ automagically mark a target sub directory as "source"

I use IntelliJ since a few months back now for my Java development. I using IntelliJ as IDE and build my projects using Maven. A couple of my Maven projects generates code which my other Maven projects depends upon, the generated code ends up in a target/src-generated directory with "Maven-subdirectories" main/java, main/resource etc. Is it possible to make IntelliJ automagically mark the target/src-generated/main/java directory as source?
Thanks in advance.
Please refer to the IntelliJ IDEA Maven FAQ:
In order to get generated sources automatically imported as source
folders configure corresponding plugins so that they put them into
target/generated-sources/<subdir>, where subdir is any folder name you
prefer. The subdir folder is necessary to distinguish sources from
different tools and also to exclude some special generated sources
(e.g. groovy stubs).
Please note that even if you manually configure
some source folders under target/generated-sources of this folder
itself, IDEA will rewrite them according to your pom.xml.
Any time you
want to generate sources you simply execute the corresponding goal,
bound for generation (usually generate-sources,
generate-test-sources). After that IDEA will pick up new folders and
set them up. Generated test sources/resources should be placed in
target/generated-test-sources/<subdir>.

Resources