I'm using Eclipse for Java Develepers (Juno x64 running on Windows 7).
I have a project in which I was trying out a jar I no longer need (args4j), so have removed the dependency. At some point, my PC lost power unexpectedly, and I've since restarted Eclipse.
My project now has an error, "Project 'MyProject' is missing required library: '/path/to/args4j-2.0.21.jar'". I was working with the project for some time after removing the dependency without any issues.
Under the Project Properties > Java Build Path, there's no reference to args4j in any of the tabs.
I've tried:
searching for the string "args4j" in all files within my project, but there are no matches. There are a bunch of references within <workspace>\.metadata\.plugins\org.eclipse.core.resources\.history\, but I'm reticent to touch them out of fear I might break something else.
[Edit] clean rebuild has no effect.
Does anyone have any idea why Eclipse is complaining, and what I might be able to do to fix it?
Please do the following, if one does not solve your problem, skip to the next one:
Check .classpath file in your project folder. You might have a reference there.
Close and re-open the project without closing eclipse, this might rebuild Eclipse resource cache.
Make a clean build after re-opening.
Re-import your project into a clean workspace.
Re-adding the problematic jar, then removing it did the trick. This is better than reconfiguring the entire workspace in my case, as I have many projects, and ADT configuration in my workspace.
I've found that the easiest and simplest way is to switch to the navigator view, open the .factorypath file and delete the offending dependency.
Deleting .classpath and .project, then reimporting the project as a Maven Project did work for me. It may also be useful to mark all Eclipse workfiles like .classpath in the p4ignore or gitignore from the beginning at the initial commit.
DO - mvn eclipse:clean eclipse:eclipse, on project and then refresh and then clean project , will solve this problem
Related
I added com.googlecode.libphonenumber to my POM file. I expected to be able to add it as required to the module-info file, but I couldn't. I can see in the .m2 directory. I can see it in the IntelliJ project .iml file.
I can see in the external dependency list along with all the other dependencies. Nothing seems wrong, yet I am not able to use the library in the project and IntelliJ suggests I import maven dependency (nothing happens, that was step 1). I tried to invalidate cache and restart. I tried deleting .idea and .iml file and re-importing the project. This is one of those times when I have nowhere to go but here. It just doesn't make sense.
requires libphonenumber; in module-info did the trick. IntelliJ was not suggesting this, I had to do it manually. Nor did it recommend it in a drop down list of possible dependencies. Java modules still need some refining.
For some of my modules Intellij IDEA is not importing the dependencies and plugins. Just the
live cycle is imported.
The poms are valid as I compile on the command line. I have deleted the modules and reimported them. I deleted the project them and re-imported it.
So I wonder if there is some secret cache where Intellij IDEA informations on modules even
after they are deleted.
Or if there is any other reason why Intellij IDEA might not be able to import dependencies and plugins.
UPDATE:
Found this interesting error message:
I don't use apache commons. Must be an Intellij IDEA problem. Maybe it is time for a bug report.
...\home\.IntelliJIdea14\system\Maven - cache for maven artifacts, you can probably delete it.
Module and project informations are stored within the project - .idea folder and *.ipr and *.iml files, you can delete them to be sure and reimport the project.
Sometimes Main Menu | File | Invalidate caches might help.
I was having an issue where IntelliJ would show compilation issues in some classes, even though running a full mvn clean install from the command line would run successfully with no errors whatsoever.
The solution for me as suggested here was to invalidate the cache and restart. I picked an option to both invalidate cache and restart.
hack: Edit your .pom file - it will trigger repo reread.
a space after version will do.
I had unresolved maven dependencies within IntelliJ for so long and it wont resolve by any means including Invalidating Cache and Restarting or deleting Maven folder within .Idea installation of machine located in system's user's account.
So eventually I had to delete the system folder located within .idea folder of the project.
It did clean my maven dependencies, resolved them again, but also erased the settings of my IntelliJ setup, so had to set Java, Maven, everything up from scratch, but it did work for me.
Even if you face some issues on Run Configurations, just build the project/module and restart the Run Configuration, that should work.
What worked for me is going to project setup and delete the dependencies from Libraries in Project Structure (Right Click Project > Open Module Settings > Project Settings > Libraries).
I had slightly the same issue when working with multiple project in InteliJ IDEA.
IntelliJ IDEA caches considerable amount of files for all projects that you have ever worked with in the IDE, hence the system cache may become overloaded.
These steps helped me to fix the issue:
Reimport Dependencies in pom.xml in the module.
IDE to invalidate cache:
From the main menu, select File | Invalidate Caches.
In the Invalidate Caches dialog, Click Invalidate and Restart.
If you click Just restart, cache files won't be deleted.
After the IDE restart follow the steps:
Right Click the Module/ Project
Click Maven Option and Select Reimport option
It went away today. Just after I fitted an 8GB memory modules to the computer. So it might have been an silent out of memory condition.
I'm trying to use the barbecue barcode printing library. I have successfully added the library to IntelliJ through project structure add library. Then I imported the packages and wrote the methods, which gave me no error. The packages were available in the class.
But when I compile it gives me the error:
error: package net.sourceforge.barbecue does not exist
How can this be?
I'm coding in ubuntu, is there any other place to which I have to add the library?
Just reimport didn't work. Following worked for me.
File -> Invalidate Caches /Restart
Then
Build -> Rebuild Project
That will reimport maven project.
Note : You need to invalidate the cache AND ALSO rebuild the project.
I tried to "Maven > Reimport" but the only thing that actually fixed it was to close the project, delete the .idea directory, and reopen the project.
None of the 13 existing answers worked for me. However, I could resolve the issue by first removing all modules:
open File > Project Structure...,
go to Modules tab,
select all modules and press the remove button,
then removing all remaining Maven modules from Maven tool window:
select all modules,
right click on them,
press Remove projects,
and then adding them again in Project tool window:
right click on root pom.xml,
press Add as Maven project,
now unignoring any ignored modules from Maven tool window:
select all ignored (grey) Maven modules,
right click on them,
press Unignore,
and finally rebuilding using Build > Rebuild project. This assumes that a mvn clean install already happened.
Right click your project / Maven (at bottom) / Reimport
Edit, much later: I also saw this happen much more frequently when I had the Clover plugin installed. Drop that plugin like a bad habit!
In my case the only thing that worked is:
mvn idea:idea
The good thing is that you don't have to delete .idea folder or .iml files and loose all configuration. Everything will be preserved.
(Possibly something like gradle idea works for gradle too).
menu -> build -> Rebuild Project
has worked for me
(Invalidating caches without this step doesn't help)
I did re-import all maven projects. This worked for me.
If you added a library to the project structure (rather than via maven, that would be different), be sure it is included as a dependency for the relevant module.
Project Structure -> Modules -> Dependencies
It's a very annoying problem which happens quite often. Especially after switching to a different git branch. It wasted me way too much time to troubleshoot this kind problem. I have tried all the methods above. But I can't find a reliable way. Here I just summarize those steps which could help in my situation. Jetbrains, please fix this issue to save your customer's precious time.
Make sure do a success command line build (If UT failed, please ignore UT by using -Dmaven.test.skip=true.
In the "Maven Projects" view, try to use "reimport" all the maven project.
In the file menu, use "Invalidate Caches"
Delete .idea folder, basically create the workspace from scratch. (That's the only reliable way can solve this issue)
In my case the problem was that there was a different repository directory configuration in IntelliJ and in settings.xml file.
Check both repository directories are the same:
IntelliJ (File > Settings > Build,Execution,Deployment > Build Tools > Maven )
settings.xml
(usually in C:\Users\myuser\.m2 or /home/myuser/.m2)
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
...
<localRepository>C:\Users\myuser\.m2\repository</localRepository>
...
</settings>
After fixing directories run:
Generate Folders and Update Sources for All Projects
Reimport all maven projects
Tried all the above approaches, didn't work.
Finally running maven clean install solved it!
Quit IntelliJ, remove every .idea directory:
rm -Rf **/.idea/
and restart.
Invalidate Caches/ Restart and then Build -> Rebuild Project helped for me
I tried all appreciated answers and none of them solve my problem!
According to Intellij community, there is a bug with Maven builds in 2020.1 and 2020.1.1 versions: https://youtrack.jetbrains.com/issue/IDEA-237320?_ga=2.235486722.203129946.1591253608-322129264.1584010541
Please try to run on 2019.3.4 version (Its worked for me from the first time)
You can download from here
https://www.jetbrains.com/idea/download/previous.html?_ga=2.190043688.203129946.1591253608-322129264.1584010541
Similar to cvdr. Too high a Java version can be the problem.
A collegaue just have this problem with multiple java sources in our test project. She had just updated to a later Intellij and when we investigated none of the rebuild options worked but Intellij seemed to have 'bumped' the project Java settings to Java 11 (I guess it takes highest installed version on upgrade install?) Setting it back to Java8 and the project compiles successfully.
Go File>Project Structure > Project Settings > Project and select the right ones in the drop downs.
I got this error after I changed pom, and I fixed it by execute:
mvn idea:module
it works for me
Here is a solution worked for me:
Disable the "Use --release option for cross-compilation like the following in intellij idea:
got Settings -> Build,Execution,Deployment -> Compiler -> Java Compiler and disable:
Use '--release' option for cross compilation(java 9 and later)
As someone who only occasionally needs to do Java work, this was very annoying. Inevitably, packages would have been added since the last time I ran our server inside IntelliJ and it would fail to build. I found what seems to be an easier solution: just don't build within IntelliJ. Build from the command line via Maven, then make sure that the run configuration does not list Build as a "Before launch" task.
I tried
"Maven > Reimport"
Deleting the .idea directory, and reopening the project.
File -> Invalidate Caches/Restart then Build -> Rebuild Project
Deleting what is inside local .m2 folder, and downloading dependencies again.
Running mvn idea:idea in Maven console (Though this command is obsolete, I had to try.)
in different combinations.
But going from Intellij 2020 version to 2019 solved my issue.
I had this problem in IntelliJ 2020.3 and tried the invalidate cache option and rebuild, but the problem persisted. The only thing that fixed it was to rename the package and rename it back to what it was originally.
I had the same problem and it was fixed for me by changing the "Maven home directory" in Settings from "Bundled" to my locally installed maven. Perhaps this triggered some kind of refresh somewhere since I had not changed this setting for months without any issue.
What happens here is the particular package is not available in the cache. Resetting will help solve the problem.
File -> Invalidate Caches /Restart
Goto terminal and build the project again
./gradlew build
This should download all the missing packages again
If you are trying the suggested ways and still no chance, be sure about your order:
Delete your .idea/
Invalidate and Restart Cache afterwards
Import maven projects from your maven tool
If you did not invalidate and restart cache just after deleting your .idea/, Intellij keeps generating it and that was keeping error in my case.
I had the same issue with my unit tests. I created tests on my master branch and early everything worked well, no matter what branch I was using. But when I switched again to master branch, tests did not work anymore.
What helped me was to:
close intellij -> delete .idea file from directory -> open project again by pom.xml (idk if it matters what way you open the project, but first time when I tried to open it normally by intellij, it still dit not work) -> reload all maven projects from right menu -> rebuild project and that's it, everything works now
I had the same problem. I fixed it by applying the android-apt plugin https://bitbucket.org/hvisser/android-apt
Maven reimport, rebuild and invalidate caches did not work. I solved it by opening a terminal and executing maven clean install in the root folder project. (IntelliJ was opened and I was able to see the IDE updating and triggering reindexation while maven was doing his job)
The above solutions didn't work for me. I had to add the dependency explicitly in the pom.xml.
Just add your jar under resources/library and then add it as a dependency in your pom.xml like:
<dependency>
<groupId>your-jar-group-id</groupId>
<artifactId>artifact-id</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/resources/library/name-of-jar.jar</systemPath>
</dependency>
Try this out if none of the above work.
Delete your .idea/
Invalidate and Restart Cache afterwards
Re-import project
If you do not want to destroy .idea, you can try :
open Project Structure > Modules
unmark the java folder as a source folder
apply / rebuild
then mark it again as a source folder
rebuild
In case you're facing very weird "unable to resolve java, sun packages problem", try the following:
Open Project Structure and change Project SDK to another version, example: java 8 -> 9; 11->13, etc, and wait until it re-index all jdk's jars. Switch between jdks with same version may not work! (Ex: jetbrains jdk11 -> openjdk 11)
Open a new project (or create a empty one); pause new project's indexing; close the old one; start indexing; open the old project and pause the new project's indexing and wait.
I am starting to configure my development environment and I am using Spring Tool Suite 2.8.1 along with m2E 1.01.
As far as I can tell, since this is a Maven Project (my first), my Maven POM is dictating (along with m2E smarts) my project build configuration and dependencies.
What I would like to know is why my IDE is displaying Java Build Problems that read "Archive required for library library/path/somejar.jar cannot be read or is not a valid zip file" when I can see the jars in my .m2 repository?
All the errors pertained to commons-logging:1.1.1 which I excluded in my parent-pom. This was a transistive dependancy via spring-context-support:3.0.5. I excluded that library from my build and now the errors pertain to the spring-context-support library.
I have attached a screenshot to illustrate.
Indeed IDEs often cache the local repository (Eclipse does something similar, and I have to relaunch Eclipse).
One ugly maven behavior you might encounter is that if you declare a dependency before you actually install it, maven will create an empty version of the missing dependency (folder with metadata but no jar), and you will have to manually clean your .m2 repository.
Third, an installed archive (jar...) can get corrupted, so try to open it with any archive tool (7zip...) to test it, and delete the whole folder if the archive is corrupted.
In my case I had to manually delete all the files in .m2\repository folder and then open command prompt and run mvn -install command in my project directory.
I was using Eclipse as IDE and I was getting very same error. I had to do Project->Maven->Update Project. Select all the checkboxes below except "offline" esp. the one "Force update of snapshots/releases" and click OK. Did the Clean Build for the Project again.
Delete corrupted files from your local .m2 repository and Ctrl+F5 (Update Maven Project) in Eclipse/STS. It'll download and install these files.
This worked for me.
Close Eclipse
Delete ./m2/repository
Open Eclipse, it will automatically download all the jars
If still problem remains, then right click project > Maven > Update Project... > Check 'Force Update of Snapshots/Releases'
Below Steps resolved my issue.
Go to ./m2/repository folder.
Go to respective archive error folder.
Verify any zip file is exist.
delete error name folder.
Now come to Eclipse Project - Right Click - Maven - > Update Project.
Above trick works for me.
For Googlers:
In my case I had accidentally manually added a Java class to the build path while poking around Eclipse. By taking a look at the 'Configure Build Path...> Libraries I removed the culprit class and now only have the
JRE System Library
Maven Dependencies
and nothing is complaining.
In my case I tried all the tips suggested but the error remained. I solved changing with a more recent version and writing that in the pom.xml. After this everything is now ok.
I deleted the local maven repository.
Then just rightclick the project -> Maven -> Update Project...
Select all concerned projects and click OK.
I was facing the same problem with my project.
My project was not able to find this archive: -
C:\Users\rakeshnarang\.m2\repository\org\hibernate\hibernate-core\5.3.7.Final
I went to this directory and deleted this folder.
Went back to eclipse and hit ALT + F5 to update the project.
The jar file was downloaded again and the problem was solved.
You should try this.
This happens when Eclipse screws up. To fix it, delete all the files in:
workspace/.metadata/.plugins/org.eclipse.jdt.core
Remove maven dependenices from build path
I faced this problem. I had "Archive for required library spring-boot-devtools cannot be read or is not a valid ZIP file" and the solution was like that:-
1- determine the dependencies names that have problems(for may case it is spring-boot-devtools).
2- close eclipse.
3- search in your .m2 file on these dependencies(by name).
4- delete these folders.
5- reopen eclipse and let maven rebuild your dependencies again.
Ok, I had the same problem with STS on a mac and solved it by deleting all the files in repository folder and from the STS IDE click on the project and then Maven -> Update project. Give it a couple of minutes to download all the dependencies and the problem is solved.
I face with the same issue. I deleted the local repository and relaunched the ID. It worked fine .
Just had this problem on Indigo SR2. It popped up after I removed a superfluous jar from the classpath (build path). Restarting Eclipse didn't help. Added back the jar to the build path...error went away. Removed the jar once again, and this time I was spared from another complaint.
none of the solutions above helped my problem. I've resolved it by deleting all files in {projectworkspace}/.metadata folder AND in {location}/.m2 folder and let eclipse download every single thing again. Hope this helps someone, cheers!
When I got an error saying "archive for required library could not be read," I solved it by removing the JARS in question from the Build Path of the project, and then using "Add External Jars" to add them back in again (navigating to the same folder that they were in). Using the "Add Jars" button wouldn't work, and the error would still be there. But using "Add External Jars" worked.
This could be due to you have added spring-licence.txt file to your web app libraries.
I had similar issue and resolved after removing that text file. In libraries it will expect jar file only.
Alternatively, below commands also worked for me:
mvn -s settings.xml eclipse:clean
mvn -s settings.xml eclipse:eclipse
In case of VSCode, follow the below steps:
Navigate to the respective folder that contains the corrupted jar
Delete just the jar
mvn clean
mvn compile
That worked for me.
Read the issue in Problems section,identify which dependency not able to read, then go the maven repository .m2\repository ->
1)check the dependencies and delete it from the folder
2)go to STS/Eclipse -> click on maven -> update project ->select the force update of snapshots/releases and click on ok.
or
delete the dependencies from the .m2/repository and rebuild the maven --> update the maven project
In my case, I just had to remove the following 2 lines from proguard.cfg:
-keep class android.support.v4.** { * ; }
-dontwarn android.support.v4.**
Yes, I know that the question refers to the Spring Tool Suite but:
Spring Tool Suite is based on Eclipse (the IDE I am currently using for ADT).
Proguard is a Java obfuscator that can be used for any project, not just Android
I tried all the suggested answers and tips in the thread and none worked for me, until I removed the references to said libs.
I hope this helps someone.
Delete your C:\Users\PC\.m2** folder
and update maven project
I'm working on a swing project, using maven2 (from command-line) and eclipse (without maven integration). So, I generate the eclipse project through maven eclipse plugin (mvn eclipse:eclipse), import it inside eclipse, and do all my work.
My problem is: when I run my app in eclipse (as a Java Application), I can't find none of the resources that are in my src directory. Digging for information on my problem, I get into this answer from another question. So, I compared the output from the following instructions:
MyClass.class.getResource("/").getPath();
MyClass.class.getProtectionDomain().getCodeSource().getLocation().toString();
Those gave me the following outputs, respectively:
${workspace_loc}/${my_project}/target/test-classes/
file:/${workspace_loc}/${my_project}/target/classes/
Checking the above locations, I could see that the former is empty, while the other one contained all my compiled classes and resources. So, I came to the conclusion that the classloader is looking for my resources in the wrong place. So, I think I have three questions:
Is my understanding correct?
If so, how it does to find the classes it is loading?
How do I solve this?
UPDATE: I've changed my code, so instead of invoking MyClass.class.getResource(...) or MyClass.class.getResourceAsStream(...), I'm now using ClassLoader.getSystemResource(...) and ClassLoader.getSystemResourceAsStream(...). In this way, everything is working fine in eclipse. I just don't know exactly why. Any hint on this?
Two possibles cases for me :
You are using eclipse to compile your project. Then eclipse is configured to exclude (or not include) resources in the src folder. You can set it in Project/Properties/Java Build Path/Source. Then you expend your src folder, and ensure you have something like "Included All", "Excluded None".
You run your maven application using maven to compile and not eclipse, even though you are using eclipse as your IDE. Then by default maven will not copy resources from the source folder to the output folder... Because it is not the standard maven way of doing things. Thus the resource are missing from the classpath and you don't find them. Just change your maven configuration to also include resources from your source folder.
I think you have to add src/main/resources to the build path. This is done in Project Properties > Build Path > Source. Here is how the standard maven project looks:
In future when using Eclipse I suggest to use m2eclipse plugin and create project using it. This will automatically make sure that all these folders are in the build path.
Try this:
Run configurations... -> Classpath -> User Entries -> Advanced... -> Add Folders
Can you try loading the resources using below?
this.getClass().getClassLoader().getResourceAsStream(propertyFileName)
This might be useful information
Eclipse Maven plugin has its own Classpath Container that conflicts with generated class paths when enabled.
What I would suggest is stop using eclipse:eclipse (sorry - harsh I know). I used it for about 8 months, cant believe it took me that long, and used M2Eclipse. M2Eclipse is an eclipse plugin in which you do the following.
Enable Dependency Management.
Update Project Configuration
(In Eclipse) Project -> Build Project
(In Eclipse) Run Application
It may not seem it, but its a much easier and less frustrating way of doing it.
Before, with eclipse:eclipse. You would have to run it then hit refresh and hope that everything is configured - if you have a multi-module pom things can really go wrong.
For me the Files within the WEB-INF were not getting included. Hence I added them to Buildpath (Project -> Build Path -> Configure Build Path -> Add folder (project/src/main/webapp). This resolved the issue.