Using Intellij + Maven to import libraries: Cannot resolve symbol - maven

I have imported a library (JBox2D) using Maven in IntelliJ 13, for use in an android project. Maven didn't give me any error messages, so I assume the library was imported correctly.
However, as soon as I try use a class from the library, I get "Cannot resolve symbol". IntelliJ doesn't offer the option of adding an import statement, as it normally does.
How should I proceed?

Open the maven window and hit the reimport button (it's usually the first one on the toolbar). This will force IntelliJ to reimport your project based on changes in your pom.
Also, check the maven settings within IntelliJ and confirm that you're configured to use the same maven in IntelliJ as you're using on the command line.
If this doesn't work, then try to explain in more detail what you mean by your having imported a library with maven?

Related

No next button when importing Maven projects in IntelliJ

I am trying to follow a tutorial on spring boot, first step is to import a maven project in intelliJ, generated by spring initializer, but when I try to do so, I have no next button in the import window, only "finish". And when I click on finish, it does not seem to detect packages. Any idea ?
Import from Maven dialog was replaced with single open action and now takes all the defaults without showing any additional dialogs with many various settings: IDEA-223880.
You may check with these guidelines.
Just type mvn install in the terminal.
or
Settings --> Build,Execution,Deployment --> Maven --> importing
Check the import Maven projects automatically
which will enable imports automatically.
Indeed all dependencies were resolved with maven build :)
Thanks guys !
Just to keep the question complete: In my case IntelliJ was unstable with JDK 12 and I had to use JDK 15. Another thing you might check is whether pom.xml is in the directory (in the past I have accidentally removed the file - type "maven" was displayed but after selecting "Maven" type there was only "Finish" and no "Next").

How do I get IntelliJ to recognize JavaFX as a dependency to a Kotlin project with Gradle?

I am finishing a project written by someone else. The project is written in Kotlin, but I could not get their build system (wemi) to recognize JavaFX, and so I ported it to Gradle instead, since the JavaFX developers have approved instructions for using Gradle (see those here). Gradle downloads these dependencies normally, and IntelliJ lists them in my external libraries, but I cannot import them into my code.
I am using JVM 11 and Kotlin 1.3.31 with JavaFX 11.0.2. I have followed these instructions to the letter, and it still does not work.
The error is upon importing classes from JavaFX. When I attempt to import a class from any JavaFX module, IntelliJ fails to resolve the 'javafx' package. No other errors appear. By all accounts, if the dependency shows in my dependency list, I should be able to import it, but this is not the case. What can I do to fix this?

Minor Annoyance: edu.emory.mathcs.backport.java.util

I know this is trivial, but I bet I am not the only developer being annoyed by this issue:
I have a maven project building a Spring Hibernate frameowrk for a webapp.
I am building using Eclipse.
I use Eclipse shortcuts to import dependencies and often do so almost subconsciously.
Somewhere in my project dependencies I have a jar that includes the following package.
edu.emory.mathcs.backport.java.util
I often accidentally import this package instead of java.util and get compile or runtime errors.
QUESTION: How can I find out which dependency includes this package so I can (hopefully) exclude it using the Maven enforcer plugin.
This does not directly answer your question but may help you prevent the accidental import in the first place:
In Eclipse you can add a type filter in Preferences → Java → Appearance → Type Filters.
From the description there:
All types whose fully qualified name matches the selected filter strings will not be shown in the 'Open Type' dialog. They will also be ignored in content assist or quick fix proposals and when organizing imports. For example 'java.awt.*' will hide all types from the awt packages.
You can run mvn dependency:tree from the command line. It will show a tree of your dependencies and their transitive dependencies.
Within Eclipse you can open your pom.xml using the Maven POM Editor (default editor for POM files) and click on Dependency Hierarchy.
Within this view you can use a filter or select the dependency on the right side and the dependency tree for this dependency will be shown on the left side.
I recently encountered this issue with a Maven project in IntelliJ IDEA.
You can view transitive dependencies using the Maven command mvn dependency:tree to figure out where this package is creeping in.
However, it's worthwhile to mention that this problem can occur for Gradle or Maven projects. If you are using IntelliJ, then another workaround that will work for all of your projects - regardless of build tool - is to exclude the package altogether from the IDE's editor settings.
The steps to exclude the edu.emory.mathcs.backport.java.util package when using auto-import for all of your projects opened in IntelliJ are as follows (this is valid for IntelliJ IDEA 2022.2):
Ctrl + Alt + S (or click on File, then Settings)
Editor > General > Auto Import
Under the exclusion section, add the following exclusion with an IDE scope: edu.emory.mathcs.backport.java.util.*
Reference Screenshot

IntelliJ Idea doesn't place dependencies in External Libraries Folder

Currently have a hard times working on one project. While building with maven I'm getting success but when I open the project all classes are red with unresolved dependencies and folder "External Libraries" contains only JDK classes.
Does anyone know what might be the reason of this?
Thanks in advance.
I'm using Intellij Idea 14.0.2 and Maven version 3.2.5
Enable auto reload for your pom file(s). intelliji doesn't do it automatcally unless you enable it.
To do so, just open a pom file and you'll see a popup that asks you if you to enable auto relaod.

intellij idea. what library uses project?

I have Android Maven project which works with Netbeans and Eclipse and compiles in command line itself, but i have some problems with Intellij Idea. After importing the project the IDE complains about non-existing method of imports:
import org.w3c.dom.Node;
cannot find symbol
symbol : method getTextContent()
The method getTextContent() added in java version 1.5. I do use 1.7 Oracles JDK. Build target in pom.xml points to 1.5
Similar post about problem in Eclipse mentioned here says:
There are many jars packaged with xml-apis and they sometimes contain the same library routines, but at different versions.
I have searched how to lookup which version of library is used with IDE and how to priorities the right libraries.
Do someone have the answer?
In intellij go to module settings (right click module and its in the context menu).
Select project, you can choose and/or add a project SDK here, If you are using 1.7 it will probably be that version.
when you make/compile your project its probably running against the version above.
You can run maven targets (in my version there is a tab on the right) you should be able to do this if you right click on the pom file, this should compile.
In conclusion
use the same java version on your pom and in your project
try to move Android SDK module up. in "Project structure" -> "Modules" -> "Dependencies". And make sure You do not have the old maven module xml-apis there.

Resources