[java] Package doesn't exist error in intelliJ

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

This question is related to java intellij-idea ubuntu-12.04 barcode

The answer is


If you are trying the suggested ways and still no chance, be sure about your order:

  1. Delete your .idea/
  2. Invalidate and Restart Cache afterwards
  3. 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 did re-import all maven projects. This worked for me.enter image description here


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.


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!


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.


menu -> build -> Rebuild Project

has worked for me

(Invalidating caches without this step doesn't help)


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.

  1. Make sure do a success command line build (If UT failed, please ignore UT by using -Dmaven.test.skip=true.
  2. In the "Maven Projects" view, try to use "reimport" all the maven project.
  3. In the file menu, use "Invalidate Caches"
  4. Delete .idea folder, basically create the workspace from scratch. (That's the only reliable way can solve this issue)

For me worked:

  1. Reimport
  2. Invalidate Caches/ Resart
  3. Rebuild Project

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)


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


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 )

IntelliJ Local Repository Configuration

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:

  1. Generate Folders and Update Sources for All Projects

enter image description here

  1. Reimport all maven projects

enter image description here


Tried all the above approaches, didn't work. Finally running maven clean install solved it!


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:

  1. open File > Project Structure...,
  2. go to Modules tab,
  3. select all modules and press the remove button,

then removing all remaining Maven modules from Maven tool window:

  1. select all modules,
  2. right click on them,
  3. press Remove projects,

and then adding them again in Project tool window:

  1. right click on root pom.xml,
  2. press Add as Maven project,

now unignoring any ignored modules from Maven tool window:

  1. select all ignored (grey) Maven modules,
  2. right click on them,
  3. press Unignore,

and finally rebuilding using Build > Rebuild project. This assumes that a mvn clean install already happened.


In case you're facing very weird "unable to resolve java, sun packages problem", try the following:

  1. 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)
  2. 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.

Invalidate Caches/ Restart and then Build -> Rebuild Project helped for me


Just reimport didn't work. Following worked for me.

File -> Invalidate Caches /Restart

Then

Build -> Rebuild Project

That will reimport maven project.


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).


I tried compile a java 8 project with JDK 12 and has the same issue. None of previous answer solved my problem.

I changed o Shortel Command Line to "JAR Manifest" and worked like a charm.

intellij


I tried

  1. "Maven > Reimport"
  2. Deleting the .idea directory, and reopening the project.
  3. File -> Invalidate Caches/Restart then Build -> Rebuild Project
  4. Deleting what is inside local .m2 folder, and downloading dependencies again.
  5. 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.


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

What happens here is the particular package is not available in the cache. Resetting will help solve the problem.

  1. File -> Invalidate Caches /Restart
  2. Goto terminal and build the project again

    ./gradlew build
    

This should download all the missing packages again


I had the same problem. I fixed it by applying the android-apt plugin https://bitbucket.org/hvisser/android-apt


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


Quit IntelliJ, remove every .idea directory:

rm -Rf **/.idea/ 

and restart.


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)


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to intellij-idea

IntelliJ: Error:java: error: release version 5 not supported Has been compiled by a more recent version of the Java Runtime (class file version 57.0) Error: Java: invalid target release: 11 - IntelliJ IDEA IntelliJ can't recognize JavaFX 11 with OpenJDK 11 Error: JavaFX runtime components are missing, and are required to run this application with JDK 11 ERROR Source option 1.5 is no longer supported. Use 1.6 or later Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6 How to configure "Shorten command line" method for whole project in IntelliJ intellij idea - Error: java: invalid source release 1.9 Failed to resolve: com.google.android.gms:play-services in IntelliJ Idea with gradle

Examples related to ubuntu-12.04

Increasing Heap Size on Linux Machines wget: unable to resolve host address `http' How to check which PHP extensions have been enabled/disabled in Ubuntu Linux 12.04 LTS? java.lang.Exception: No runnable methods exception in running JUnits Speed up rsync with Simultaneous/Concurrent File Transfers? MySQL Job failed to start CronJob not running libz.so.1: cannot open shared object file error: could not create '/usr/local/lib/python2.7/dist-packages/virtualenv_support': Permission denied Package doesn't exist error in intelliJ

Examples related to barcode

NSCameraUsageDescription in iOS 10.0 runtime crash? Package doesn't exist error in intelliJ How to Generate Barcode using PHP and Display it as an Image on the same page Integrating the ZXing library directly into my Android application How to read barcodes with the camera on Android? QR Code encoding and decoding using zxing Using ZXing to create an Android barcode scanning app Free Barcode API for .NET BarCode Image Generator in Java How can I scan barcodes on iOS?