Missing tools.jar in local repository breaks m2eclipse - java

The problem I'm experiencing is that eclipse can't resolve any of the dependencies of my project. This causes problems because even though the dependencies seem to work alright when coding (I get autocompletion) I still get a huge list of errors referring to missing artifacts.
When filtering these, I found the following:
The container 'Maven Dependencies' references non existing library '/home/[...]/.m2/repository/com/sun/tools/1.5.0/tools-1.5.0.jar'
It seems that this dependency was introduced by struts2, who have a profile set up as follows in their pom:
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
That systemPath resolves and so I don't see a reason why this would be causing trouble. In any case, is there a way to tell eclipse that this m2eclipse dependency is a system dependency that is not found in the local repository?

I was facing the same problem and needed to do the following things
Added -vm path/to/jdk/bin in eclipse.ini file
Clean the existing workspace and reload the project.
It worked for me seamlessly.
Its worth to add that, in my eclipse.ini file I had to add the -vm ... lines at the top of the file. like
-vm
C:\Program Files\Java\jdk1.6.0_27\bin
... ... ...
Make sure that, -vm option is placed before -vmargs as everything after -vmargs is passed directely to vm and selecting a particular is depend on -vm option.

I had this issue, but I have fixed by using the steps below:
Case1:
Eclipse by default pointing to JRE but eclipse maven plugin required JDK so point to JDK
Window -> Preperences -> Java -> Installed JREs
change it to JDK
Follow the steps to change to JDK from JRE
In the Eclipse IDE go to: Window… Preferences… Installed JREs
Select defaulted JRE and click on Edit.
Click on Add External Jar
I found tools.jar in “C:\Program Files\Java\jdk1.6.0_22\lib” and added.
Now I can build my project without any issue. Is this the correct way to solve this issue?

I had the same problem - Eclipse couldn't find a tools.jar. As I found out the reason is that Eclipse used a JRE and not a JDK. You have to add a -vm parameter to eclipse.ini that is pointed to your JDK bin directory:
...
-vm
path_to_jdk\bin
...
This should fix the problem.

excludes tools jar from the struts dependency.
<exclusions>
<exclusion>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
</exclusion>
</exclusions>

Download http://repository.ops4j.org/maven2/tools/tools/1.5.0/
and put the jar in the C:\Documents and Settings\Administrador\.m2\repository\com\sun\tools\1.5.0. Good luck.

You need to verify that Eclipse is using JDK installs.
In Eclipse IDE go to
Window / Preferences / Java / Installed JREs
point to a JDK installation.
For example: C:\Program Files (x86)\Java\jdk1.6.0_37

I read this and tried various things. What worked for me was this: I changed the windows --> preferences --> java --> installed JREs to point to the JDK instead. That solved this problem.

As strange as this may sound, I solved this issue by just re-synchronizing with the SVN repository.
The thing is, I took the entire workspace from another PC, so when I imported the maven project using the m2e plugin, maybe some dependencies didn't synchronize correctly.
I'm posting this just in case someone is desperate with this error and trying all possibilities.

In each project you import into Eclipse, Eclipse makes some files on filesystem - .project, .classpath, a folder .settings,. It seems that Eclipse doesn't update these correctly.
Delete these and import them again.
Clearly, this workaround won't work if this is your 1st import and you already have obtained some issues. Than have a look here Maven2: Missing artifact but jars are in place

I also had a similar issue and fixed it the following way. Go to lib directory of JDK installed path in command prompt. Execute the below command to install to install tools.jar.
$mvn install:install-file -DgroupId=sun.jdk -DartifactId=tools \
-Dpackaging=jar -Dversion=1.6 -Dfile=tools.jar

<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6.0</version>
<scope>system</scope>
<systemPath>${env.JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>
Just add this. It will work.

This dependency should work as expected. If in doubt, try the command line version of Maven because the Eclipse plugin is very brittle when it comes to dependency resolution.
Unlike other parts of Eclipse, it is unable to create even a partial classpath for the build if something is wrong with the POM, so the error could be something else.
If all else fails, try to install the file into your local repository, so you can see the next error.

I eventually found what was causing it. Seemingly it's a bug in m2eclipse when you are using maven1 repositories. I still had the java.net maven1 repository in my pom; after disabling it everything works again. A very annoying problem to track down because in the end it had nothing to do with finding the tools jar.

For Mac users
[1] To find out where your VM is type this
/usr/libexec/java_home
[2] vi ./Eclipse.app/Contents/MacOS/eclipse.ini
[3]
-vm
/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/
-vmargs
........
........
[4] In Eclipse , Update Maven
[5] Sing All is Well :-)

I had the same issue several times and I could fix it following two steps:
I added "-vm C:\\bin" to eclipse.ini or to the link from which I run eclipse.
After having this problem many times, I began to suspect that there may be some m2eclipse cache that is reloaded after some time (one day or so), so I tried a weird solution: temporarily changing the computer time to the following day and restarting Eclipse or closing/cleaning the project and.... IT WORKED!!!
I could repeat the process several times successfully.
A more elegant solution (I haven't had the chance to try it yet), might be to clear m2eclipse caches mentioned at https://stackoverflow.com/a/16444984.
Hope this will help anyone.

This issue due to wrong java configuration. every IDE required full JDK pack. becuase tools.jar available inside JDK lib not jre lib
go to control panel change environment path variable to C:\Program Files\Java\jdk1.8.0_31\jre\bin.
change JAVA_HOME to C:\Program Files\Java\jdk1.8.0_31.
open IDE(eclipse or STS) change JRE system library to C:\Program Files\Java\jdk1.8.0_31
then restart IDE. it will work

A hacky solution that worked for me:
If m2e is complaining that the following jar is not found in the Maven cache (you can find the bad path in the error log for the pom file, or in the "Java Build Path > Maven Dependencies" list):
${HOME}/.m2/repository/jdk/tools/jdk.tools/1.6/jdk.tools-1.6.pom
then try the following command (fill in JAVA_VERSION_HERE for an installed JDK, e.g. jdk1.8.0_191-amd64, then use the two path sections after .m2/repository/ above to determine the correct groupId, and replace 1.6 with whatever version m2e is complaining about -- it may or may not matter if the JDK you have installed matches the version m2e is complaining about):
mvn install:install-file -Dfile=/usr/java/JAVA_VERSION_HERE/lib/tools.jar \
-DgroupId=jdk.tools -DartifactId=jdk.tools -Dpackaging=jar -Dversion=1.6
This command copies tools.jar from your JDK and puts it into the Maven cache, also creating a pom.xml file for it so that it can be used by Maven.

Related

Eclipse Maven 2 installation

I am doing a Maven build in Eclipse where my project requires Maven 2. My Maven runtime is set to embedded (3.2.1/1.5.1.20150109-1819). How do I set the runtime to use Maven 2?
I tried setting a runtime installation by pointing to my Maven 2 installation, but that did not work.
I pointed to libexec folder lying along bin, and it worked.
I found the details of a similar issue, with the M2E plugin, below is the link.
https://dev.eclipse.org/mhonarc/lists/m2e-users/msg05131.html
It might help to upgrade the m2e version.
http://download.eclipse.org/technology/m2e/releases/
Actually you have selected the wrong folder of maven. When you have unzipped the file directory will look like
you should have select directory pointed by red highlighter.
you should select the red highlighted folder. In your case you are pointing bin directory that's why it is creating problem.
Please do not forgot to click on your installed maven.
This has resolved my issue.

Maven 3.3.1 ECLIPSE: -Dmaven.multiModuleProjectDirectory system propery is not set

I just installed Maven 3.3.1 on Mac OS X, and building a Maven Project with Eclipse is giving me this error:
-Dmaven.multiModuleProjectDirectory system property is not set.
Check $M2_HOME environment variable and mvn script match.
It did not happen before with Maven 3.2.5.
Is there any way to fix this (except downgrading to 3.2.5) ?
Where exactly can I set this "multiModuleProjectDirectory" property in Eclipse?
In Eclipse you need to go like this.
Window-> Preference -> Java -> Installed JREs -> Edit
In the edit Default VM arguments you need to put
If you already set the maven home.
-Dmaven.multiModuleProjectDirectory=$M2_HOME
In IntelliJ you can set this option in VM Options field that you can find in the next configuration view:
Preferences/Build, execution, deployment/Build tools/Maven/Runner
This was filed as a bug with m2e in Eclipse at https://bugs.eclipse.org/bugs/show_bug.cgi?id=462944 , due to the changes in Maven 3.3.1.
This is fixed in m2e 1.5.2 as of 2015-04-13. This is an available release that can be installed from http://download.eclipse.org/technology/m2e/releases/ .
(No more changing JVM arguments for the entire workspace or for specific launch configurations required.)
Define like this in the JVM options:
-Dmaven.multiModuleProjectDirectory=HOME_PATH_OF_YOU_PROJECT
In case you have this error message on your commandline, please verify if your PATH variable points to the same maven installation apache-maven-3.X.X/bin folder as your M2_HOME variable. In my case I was mixing up two versions which resulted in this error.
go to run configuration, create new maven build launch configuration where in the first tab you fill the base directory and the goal,
then, go to jre tab and add to the vm args this config:
-Dmaven.multiModuleProjectDirectory=%M2_HOME%
where M2_HOME is an environment variable pointing to the base directory of your maven installation
If you want to try a second way, you can try to download a path from http://download.eclipse.org/technology/m2e/milestones/1.5/.
Open Help>install new software and download from url above. This way solved my problem.
I encountered the same issue with Maven 3.3 and 3.2 versions, so I decided to downgrade it to version 3.0.5 and it worked just fine.
To set the maven.multiModuleProjectDirectory property permanently in Maven, I've added a default activated profile which initializes the property with the MAVEN_HOME environment variable in the settings.xml file. Or you could also alternatively use the M2_HOME environment variable.
<profile>
<id>my-profile</id>
<properties>
<maven.multiModuleProjectDirectory>${env.MAVEN_HOME}</maven.multiModuleProjectDirectory>
</properties>
</profile>
<activeProfiles>
<activeProfile>my-profile</activeProfile>
</activeProfiles>
i had the same problem with intelliJ 14, i tried out different solutions provided at forums but not worked out. What i did is i completely uninstall intellij and installed intellij 15.0.1 and import the same project then all works fine.

which maven is used in IntelliJ for right click->maven->reimport

In our company we use a patched maven3 which replaces
a <version>${com.foo.bar.version}</version> placeholder with a real version before doing all the maven stuff. Might not be a great ideas, but I can not change this fact.
All works fine with command line mvn commands.
In IntelliJ I have set maven home dir to the correct location of the patched maven.
But right click->maven->reimport does not work.
In the module settings I see that the dependencies of my module have wrong versions.
Is right click->maven->reimport using mvn dependency:tree of the patched maven? Or does IntelliJ uses some own implementation?
Following is from the console in IntelliJ's maven projects install goal
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java -Dmaven.home=/usr/share/java/patched/maven-3.0.3 -Dclassworlds.conf=/usr/share/java/patched/maven-3.0.3/bin/m2.conf -Didea.launcher.port=7536 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 13 CE.app/bin" -Dfile.encoding=UTF-8 -classpath "/usr/share/java/maven-3.0.3/boot/plexus-classworlds-2.4.jar:/Applications/IntelliJ IDEA 13 CE.app/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher install
Does this mean it uses a java maven implementation in /usr/share/java/maven-3.0.3/boot/plexus-classworlds-2.4.jar and not the maven executable in the path to our patched maven ?
B.t.w I found out, that version-variables <version>${com.foo.bar.version}</version> are ok, they just not possible in the parent/reactor pom
I won't even ask why it was necessary to use a "patched" maven (it seems like a very bad idea), but in any case: I am reasonably confident that intellij is using it's own in-memory dependency analysis when you invoke the reimport action.
Perhaps you are best to use a maven profile that sets the correct version for your development environment and build with -Pmyprofile.

Struts2 exclude com.sun:tools:jar:1.5.0 required?

I am new to Struts2.
Whenever I include the Struts2 dependency, why do I have to do like this?
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>${struts.version}</version>
<exclusions>
<exclusion>
<artifactId>tools</artifactId>
<groupId>com.sun</groupId>
</exclusion>
</exclusions>
</dependency>
If I don't do this, Eclipse Juno gives me error at this point.
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd
With this error:
Missing artifact com.sun:tools:jar:1.5.0
Is this the way to do it or is there a better way?
I noticed that this problem happens from version 2.1.6 and higher.
The artifact com.sun:tools:jar:1.5.0 is a jar from the JDK (not the JRE). This jar is not available in any maven repository but is located in <JDK_HOME>/lib. That's why you get this error.
When you specify an exclusion, maven won't try to find the jar (and so it won't fail).
Struts2 requires this dependency at compile time (not at runtime).
So setting an exclusion is the correct way of getting rid of this problem. Since maven need a JDK to run: the tools.jar will be available anyway when compiling the project.
You should not need to do this.
That you do indicates there's an issue in your Eclipse, Eclipse project, and/or Eclipse Maven plugin configuration. By way of comparison, I have S2 projects for essentially every version, and in no pom do I need to exclude the Java tools jar, and never have.
PROBLEM EXPLAINED
Actually, what happens is that struts2 relies on a system dependency, namely tools.jar. This dependency is found by resolving this path: ${java.home}/../lib/tools.jar.
If you compile your project with maven, maven will be clever enough to replace ${java.home} with the right JDK location.
For some reason, if you try to compile your mavenized project with eclipse (ie with m2e help generally), ${java.home} is resolved against the -vm eclipse command line parameter.
SOLUTION
If you want to solve this issue, DO NOT exclude the tools.jar. Instead force your eclipse to run with your favorite JDK in either of the following ways (since I don't know your OS, I'll give examples in an OS agnostic form):
Command line switch
/path/to/eclipse -vm /path/to/jdk/bin/javaw
Check this SO answer for an example on Windows.
eclipse.ini
-vm
/path/to/jdk/bin/javaw
Check this SO answer for an example on Windows.

IntelliJ inspection gives "Cannot resolve symbol" but still compiles code

Platform: IntelliJ Community Edition 10.0.3
SDK: jdk1.6.0_21
OS: Windows 7
So I have a strange situation with IntelliJ that has me completely stumped. I setup a Maven project and add log4j as a dependency in the pom.xml file. The IDEA inspections run fine and my unit tests all compile and run.
I then added hunnysoft's jmime library to my local maven repository using the mvn install:install-file as follows.
mvn install:install-file -Dfile=jmime.jar -DgroupId=jmime \
-DartifactId=jmime -Dversion=3.1.1e -Dpackaging=jar
Maven installed the jar file just fine into my local repository.
I then went into IntelliJ's Settings => Maven => Repository Services and Updated my local repository (so that IntelliJ would reindex the repository contents).
Finally, I added the following dependency to my pom.xml file (just above the log4j dependency).
<dependency>
<groupId>jmime</groupId>
<artifactId>jmime</artifactId>
<version>3.1.1e</version>
</dependency>
I now create a new class as follows:
package com.stackoverflow.question;
import org.apache.log4j.Logger;
import com.hunnysoft.jmime.ByteString;
import com.hunnysoft.jmime.Field;
import com.hunnysoft.jmime.FieldBody;
public class StackOverflowQuestion {
public Field create(String name, String text) {
Logger.getLogger(getClass()).debug("create entered");
FieldBody body = new FieldBody();
body.setText(new ByteString(text));
Field field = new Field();
field.setFieldName(name);
field.setFieldBody(body);
return field;
}
}
Now for the weirdness. IntelliJ's intention mechanism picks up and recognizes the Logger import in the maven pom file just fine. However, for all of the hunnysoft imports it reports: "Cannot resolve symbol 'ByteString/Field/FieldBody'", BUT Build => Compile 'StackOverflowQuestion.java' compiles everything correctly and the unit test I created for this class runs fine (though the intentions mark the call to create() as a problem area too).
So somewhere, somehow IntelliJ is ignoring the jmime.jar file for the intention subsystem. I'm confused because the log4j dependency works fine and everything compiles and runs fine. F12 ("Go To Declaration") works on the Logger import, but breaks on all the jmime imports.
Oh, one other thing, if I go to the 'Packages' view in the "Projects" window the "com.hunnysoft.jmime" package appears and I can see ALL of the classes I imported in the code snippet above under "Libraries". Removing the above dependency from the pom.xml file causes this package to disappear and the compilation breaks.
It appears that the inspection's classpath is broken, but there does not seem to be a setting for this anywhere in the Settings => Intentions | Compiler areas (not that I expected any such settings, I believe the IDEA should already know the correct classpath based on the pom file and JDK).
As a final experiment I created a brand new standard J2SE application project (without using maven) and added the jmime.jar file directly to the project as one of its libraries. I run into exactly the same problems as described above in this new project.
Here is the MANIFEST.MF from the jmime jar file.
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.5.4
Created-By: 10.0-b23 (Sun Microsystems Inc.)
Name: com/hunnysoft/jmime/
Sealed: true
Specification-Title: Hunny JMIME
Specification-Version: 3.1.1
Specification-Vendor: Hunny Software, Inc.
Implementation-Title: com.hunnysoft.jmime
Implementation-Version: 3.1.1E
Implementation-Vendor: Hunny Software, Inc.
I don't see anything unusual in this jar file.
My best guess is that perhaps the problem might be a missing dependency issue. But AFAIK jmime is supposed to be self contained (JarAnalyzer doesn't come up with anything, but I'm not sure it would if a dependency jar is missing).
So, anyone have any IDEAs?
First of all you should try File | Invalidate Caches and if it doesn't help, delete IDEA system directory. Then re-import the Maven project and see if it helps.
In some weird cases compiled classes may report wrong info and confuse IDEA. Verify that the classes from this jar report correct names using javap.
The following trick resolved this issue for me:
Right click on the code editor
Hover on Maven and expand
Click on Reimport
My idea version is 12.0.4
None of the solutions above worked for me. What did was removing the main.iml file manually and it suddenly worked.
This was mentioned in another answer to this same question here, but this alone fixes this for me. I do all my builds in a separate terminal, outside of IntelliJ. So the cache's need to have the proper permissions set for the IntelliJ app to read them.
Run it from the project's root folder.
$ mvn -U idea:idea
For Gradle users:
You may need to synchronize your project with your build.gradle file.
You can right-click on your gradle file under the Project pane to do this, but that didn't seem to do anything for me (I suspect a bug in my version). You'll know if this happens because it wont' kick off any IntelliJ tasks that you will be waiting on. Instead, open up the Gradle Tool pane, then click the synchronize (refresh) button. This worked for me where invalidating the cache and restarting did not.
My own circumstance: I was using a Scala project with Gradle and had to do this.
One extra step, when I did File -> Invalidate Caches and restarted the IDE, open a project. It popped up a toastbox on the top-right asking me whether to enable auto-import and that solved the problem.
Inconsistent/duplicate module names in project structure was causing this issue for me.
Go to File -> Project Strucutre -> Modules
In Click on modules which have red underline
Got to "Dependencies" tab
Make sure the dependencies which are red actually exist in dependency list. If not, rename them to match existing dependency names
This can happen when IntelliJ doesn't shut down properly and thus cannot properly save renamed module names.
Another thing to check: Be sure that dependencies are not duplicated. In my case I found that a module exhibiting this behavior was misconfigured as follows: it had a dependency on another module, and it had a dependency on a jar produced by that other module. This meant for every symbol referenced in duplicate, and was ambiguous.
Has a fixed been published? Appears issue originally affected v11/12 due to a "Compiler overhaul" back in 2013. With discussion on related issues in Jira up to end of 2014.
http://youtrack.jetbrains.com/issue/IDEA-98425
Also on Jira IDEA-98425 was marked fixed but unverified (on v12.0.3). None of the following work-around helped resolve this "Unable to Resolve Symbol" issue with Version 13.1.1 on Windows
a. Delete .IdealIC13 folder (Then, File \ Invalidate Caches / Restart)
b. From Maven Projects window,
b.1 mvn -U idea:idea –〉Executing this maven goal suppose to reload the dependencies. This works prev, but since last FRI, executing this maven goal failed as it tried to recompile the project (Of course it fails as "Unable to resolve Symbols", that's what I am trying to fix by running this command in the first place) mvn -version — shows maven version referenced 3.2.5 and that it's working
b.2 Simply right click project, and Reimport
b.3 File \ Invalidate Caches / Restart
c. Tried both Enable & Disable this setting: File -> Settings -> Maven -> Importing -> "Use maven3 to import project"
d. Settings \ Maven \ Multiproject build fail policy = Fail at end (instead of Default)
Nothing works. What's happenning to IntelliJ support on Maven.
https://youtrack.jetbrains.com/issue/IDEA-99302
From JetBeans release history, https://www.jetbrains.com/company/history.jsp
IntelliJ v14 NOV 2014
IntelliJ v13 DEC 2013
I'd assume v12 fixed (although unverified) would be incorporated in subsequent releases. Any one having similar problems with which IntelliJ version? Please share your experience. IntelliJ maven support seems broken.
Press "shift" two times > "Reimport All Maven projects" always works for me.
None of the other answeres worked for me. My imports were not being resolved because IntelliJ pointed to wrong .m2 file.
IntelliJ Version: IntelliJ Idea 2018.1.5
My location for the .m2 directory was pointed to the wrong path. All I did to fix it was re-point IntelliJ to the right .m2 directory and update it.
First, go to: File->Settings->Build, Execution, Deployment->Build Tools->Maven
I had to change the User settings file: and the Local repository: to the correct location of my .m2 directory.
After this go to: File->Settings->Build, Execution, Deployment->Build Tools->Maven->Repositories
and click the Update button.
I'm jealous of all of you who resolved through File / Invalidate caches. I just spent hours trying everything on this question and a few others from around the web.
The magic menu item didn't do it for me so I invalidated the caches myself by nuking %USERPROFILE%\AppData\Local\JetBrains\IntelliJIdea2020.3\caches
Once I did this and restarted IntelliJ (2020.3), the indexes were rebuilt and my errors went away.
My Project Structure:
src -> main -> scala -> mypackages
What worked:
Right click on the scala folder, and click "Mark Directory as Sources Root".
I had problem with Maven Importer JDK - somehow it switched itself to JDK 11, but Maven Project reload worked only with JDK 8.
Update 2022
IntelliJ 2022.1 has an interactive, step-by-step process File -> Repair IDE. It leads you through 5 steps in sequence to try and resolve this problem for the current project before invalidating the caches for all projects. From the IDEA documentation:
Refresh Project Indexes
Rescan Project Indexes
Reopen Project
Drop Shared Indexes
Reindex Project
Invalidate Caches and Restart
Steps 1- 3 fixed it for my project.
In v2022.3 and the new UI, this setting is now in File -> Cache Recovery -> Repair IDE. You can also select an individual step from there.
If your maven project is a multi-module project, check if some of the modules are ignored by intellij.
Click on View -> Tool Windows -> Maven Projects, and check if some modules are ignored(Ignored modules are in grey, e.g. gs-multi-module in the following image).
Right click on the ignored module and choose Unignore Projects.
Then wait for intellij to finish indexing, after which it will work.
For Gradle projects:
Exit IntelliJ IDEA
Delete the <problematic-project-root>/.idea directory
Delete the <problematic-project-root>/.gradle directory
Delete all .iml files in <problematic-project-root>
windows command prompt: DEL /S /Q *.iml
linux: find . | grep -e .iml$ | xargs rm
Re-import the project into IntelliJ IDEA with Gradle
In IntelliJ IDEA 2020.3, select:
File > Invalidate Caches / Restart... > Invalidate and Restart
When prompted with Download pre-built shared indexes:
don't import the shared indexes: close the dialog or choose More actions > Don't show again
Yes, sounds like you have to create libraries containing the JARs you need and add them as a dependency in your module.
For another alternative.
I got this problem also when I used JDK7_07. I tried all answers here (except deleting IDEA System Directory). But, I still got the problem. So what I did it is:
Install newest JDK (it was JDK7_45), and set the Intellij's JDK to the new one, and it works.
Re-importing the project worked for me.
Right Click on Project -> Maven ->Reimport
when I did File -> Invalidate Caches and restarted the IDE,open a project. It showed a dialogue on the top-right "Maven changes detected" and gave an option to import and enable auto-import. Even after importing the project here, I had the same issue. The above step solved the problem.
Suggested solutions did not work. I had to unignore several projects, by right clicking on the pom => maven => unignore project.
Then after a
mvn clean install -T 6 -DskipTests
in the console, IntelliJ was happy again. No idea how the projects became ignored...
Sometimes, I just open project structure, and click project, then choose a SDK version.
In my case, I am trying to open a spring boot project from IntellijIdea got the same issue like unable to import all spring related files.
Then I did:
File -> Close Project -> Import Project -> Import from external model -> Choose Gradle -> Next -> Select the project from file location -> Finish
Now everything working fine as expected.
I have seen many answers here but I finally found this solution. It may use for someone like me.
I just had this issue and it would just not go away. I eventually wiped out the IntelliJ config directory in ~ and rebuilt my IntelliJ project from scratch. (This only took about 15 minutes in the end, compared to spending an hour trying to work out problems with cached files, etc.)
Note that my guess is that the initial problem was caused by something like javathings.blogspot.com/2009/11/too-many-open-files-in-intellij-idea.html (NB: as of 2018, that link is dead, but archive.org has a copy of the page from around when this answer was first written -ed.) or a disk space/memory issue causing Java to crash. IntelliJ seemed to just get corrupted.
After invalidating my cache and restarting; and confirming my maven settings were okay, I was still seeing "Cannot resolve symbol" for a module that I definitely had set as a dependency. Turns out I had it set to the wrong scope.
You can check by right clicking on your module and selecting Open Module Settings. Click the dependency tab and verify that the scope for your un-resolvable dependency is set to Compile.
Open "Settings"
Search for "Maven"
Click on "Ignored Files" under "Maven"
Uncheck the pom.xml files contains the missing dependencies
Click "OK"
Click File -> Invalidate Caches/Restart...
Click "Invalidate and Restart"
mvn idea:idea worked for me. Found it here. Spent more than an hour, hope it helps someone
In my case, my project was using Lombok and I was missing the Lombok Plugin in IntelliJ. After installing it everything worked fine.
I tried
File -> Invalidate and Restart
which did not worked for me.
Solution that really worked :
Project Structure -> Modules -> select target folder -> Right click generated-sources and select sources -> Apply -> ok

Categories

Resources