How do I step into the source code of the JUnit plugin in IntelliJ? - intellij-idea

When I run my test in debugging mode in IntelliJ (2017.2 Community Edition), the source code is only available for some of the code.
In particular, when I step through code in the package com.intellij.junit4, the debugger shows the method name and line number in the stack view, but the code doesn't appear in the editor.

You need to add the jar containing the source code to the class path of the project. The jar is located at the path plugins/junit/lib/junit-rt.jar relative to the folder that IntelliJ is installed into.
Go to "Project Structure" > "Libraries" > "+" > "Java" and add the path of the Jar.
See also this answer.

Related

Module is not listed in IntelliJ "Run Configuration"

Setup:
I have imported the Git project into IntelliJ.
I compiled the project using "make compile"
Issue:
I tried to create a "Run Configuration". The Module is not listed in the drop-down window.
Debugging:
I compared it with a working setup wherein a project was created using "File->New Project" and wherein .iml was automatically created. I see that the problematic project does not have a .iml file. I could not make out any other differences.
Is the absence of .iml file the root-cause for the issue? If so, how to generate this .iml file? Rather than manual writing, I prefer to generate it using GUI to avoid any manual errors. Please suggest.
In Eclipse IDE, one can convert a project from one type to another. Ex: normal project to Maven project. A default project to Java project by editing .project file.

Intellij Idea Can't add Selenium sources.jar file

I started to learn Selenium.
After creating the project I tried to add some jar files.
As you see all required jars were added. But
...sources.jar
looks like Empty Project. Why this is happening?
Probably this happening because ...source.jar file has a multiple files.
Click Libraries from Project Settings
+and add this .jar file here first.
When you added turn back to Modules
After these steps "Empty library" error is gone.

How to see java files in project tree in intellij idea?

I'm working with intellij idea but I can't see the java source files in the project tree. I see the packages, I can open it, but the class files are not displayed. Any idea? This has worked until a few days ago...
Under the intelliJ IDEA 14.0.3 community edition, upon launch I don't see my project folders. I found by going into
View > Tool Windows > Project
seems to show the folder structure.. Same as ALT + 1
Below the menubar , on the left there is a dropdown which in your case may be showing "packages" now (because you can see the packages). From the same dropdown, select "Project Files" below "SCOPES"
You need to check out the project correctly if you are checking out from SVN repo or you must not have selected correct project folder.
You can also configure your project from File->Project Structure check your Source folder is excluded or not.
Also Alt+1 will give you project structure of files in tree format
Check in "Project Structure" (ctrl+alt+shift+S) if you didn't set your source as "Excluded" (in Modules, sources).
If you are develop a maven project, you could run mvn idea:idea and then open the project in your Intellij, the source files and the project tree would become the shape you like.

Adding Jar files to IntellijIdea classpath

I have created a new Intellij project. But I can't use the third party jars in my project. I have the jars in a directory structure as follows:
repository/commons-logging/commons-logging-1.0.4.jar
repository/commons-lang/commons-lang-2.1.jar
etc.
I want to add them just by pointing to the repository directory, but couldn't find any ways to add them.
But when I am using classes or API from that jars, the editor can't resolve the classes.
I have tried from Project Structure but can't configure it.
Go to File-> Project Structure-> Libraries and click green "+" to add the directory folder that has the JARs to CLASSPATH. Everything in that folder will be added to CLASSPATH.
Update:
It's 2018. It's a better idea to use a dependency manager like Maven and externalize your dependencies. Don't add JAR files to your project in a /lib folder anymore.
If, as I just encountered, you happen to have a jar file listed in the Project Structures->Libraries that is not in your classpath, the correct answer can be found by following the link given by #CrazyCoder above: Look here http://www.jetbrains.com/idea/webhelp/configuring-module-dependencies-and-libraries.html
This says that to add the jar file as a module dependency within the Project Structure dialog:
Open Project Structure
Select Modules, then click on the module for which you want the dependency
Choose the Dependencies tab
Click the '+' at the bottom of the page and choose the appropriate way to connect to the library file. If the jar file is already listed in Libraries, then select 'Library'.
On the Mac version I was getting the error when trying to run JSON-Clojure.json.clj, which is the script to export a database table to JSON. To get it to work I had to download the latest Clojure JAR from http://clojure.org/ and then right-click on PHPStorm app in the Finder and "Show Package Contents". Then go to Contents in there. Then open the lib folder, and see a bunch of .jar files. Copy the clojure-1.8.0.jar file from the unzipped archive I downloaded from clojure.org into the aforementioned lib folder inside the PHPStorm.app/Contents/lib. Restart the app. Now it freaking works.
EDIT: You also have to put the JSR-223 script engine into PHPStorm.app/Contents/lib. It can be built from https://github.com/ato/clojure-jsr223 or downloaded from https://www.dropbox.com/s/jg7s0c41t5ceu7o/clojure-jsr223-1.5.1.jar?dl=0 .

How to generate a jar from a java module in IntelliJ with the dependencies placed in a separate directory?

I have a module for which I want a jar to be created. So, here is what I do:
Adding a jar artifact, using the "From module with dependencies ..." option
In "Jar files from libraries" I select "copy to the output directory and link via manifest"
Leave all the defaults.
After that I can build the jar and all the dependencies would be placed near it in the same directory. So far so good.
Now I wish all the dependencies to be placed in a separate directory near the final jar. So, I repeat the same steps, but this time I create a new directory under the node in the artifact Output Layout tab (using the "Create Directory" button). Next I drag all the dependencies onto the new folder and apply the changes.
On the surface, everything is cool - the dependencies are indeed placed in the dedicated directory, but the MANIFEST.MF file is never updated! It should reference the dependencies via the new directory. As of now, the produced jar cannot be run - its dependencies are not visible.
This is unlike Eclipse, which does make sure the manifest file is correct when exporting a project as jar.
How can I workaround this problem, given that:
I want all the dependencies in a dedicated folder.
I want to use IntelliJ IDEA
I do not want to edit the manifest file manually.
I am using the latest download of the IntelliJ IDEA for windows - 11.1.2, build 117.418
Thanks.
At the moment you have to update the classpath manually in the artifact configuration dialog so that it includes the subdirectory:
I've created an issue for this limitation, please star/vote.