问题
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?
Thanks. Tika
回答1:
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.
回答2:
Just reimport didn't work. Following worked for me.
File -> Invalidate Caches /Restart
Then
Build -> Rebuild Project
That will reimport maven project.
回答3:
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!
回答4:
menu -> build -> Rebuild Project
has worked for me
(Invalidating caches without this step doesn't help)
回答5:
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
回答6:
Tried all the above approaches, didn't work.
Finally running maven clean install
solved it!
回答7:
Quit IntelliJ, remove every .idea
directory:
rm -Rf **/.idea/
and restart.
回答8:
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.
回答9:
Invalidate Caches/ Restart and then Build -> Rebuild Project helped for me
回答10:
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)
回答11:
I did re-import all maven projects. This worked for me.
回答12:
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.
回答13:
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.
回答14:
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)
回答15:
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
回答16:
I had the same problem. I fixed it by applying the android-apt plugin https://bitbucket.org/hvisser/android-apt
来源:https://stackoverflow.com/questions/20137020/package-doesnt-exist-error-in-intellij