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?
Line
1,4913 gold badges18 silver badges41 bronze badges
asked Nov 22, 2013 at 4:28
5
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.
![]()
Mehraj Malik
14.1k15 gold badges57 silver badges83 bronze badges
answered Mar 16, 2017 at 8:53
Durgesh SutharDurgesh Suthar
2,6344 gold badges19 silver badges22 bronze badges
6
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.
answered Jun 2, 2016 at 19:59
mattalxndrmattalxndr
8,7797 gold badges55 silver badges87 bronze badges
7
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
Modulestab, - 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.
answered Jun 6, 2019 at 7:54
![]()
fxnnfxnn
8986 silver badges19 bronze badges
8
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!
answered Aug 4, 2015 at 20:24
humanityhumanity
9808 silver badges14 bronze badges
1
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).
answered May 10, 2020 at 18:13
![]()
daemon_niodaemon_nio
1,3361 gold badge14 silver badges19 bronze badges
1
menu -> build -> Rebuild Project
has worked for me
(Invalidating caches without this step doesn’t help)
answered Mar 23, 2018 at 22:42
AndrewAndrew
35.5k11 gold badges138 silver badges110 bronze badges
1
I did re-import all maven projects. This worked for me.
answered Aug 13, 2019 at 5:17
![]()
krishna Ramkrishna Ram
6193 gold badges9 silver badges20 bronze badges
1
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
answered Nov 22, 2013 at 19:34
![]()
vikingstevevikingsteve
37.6k23 gold badges108 silver badges154 bronze badges
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)
answered Nov 19, 2018 at 22:16
Jianwu ChenJianwu Chen
5,0883 gold badges28 silver badges32 bronze badges
4
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:Usersmyuser.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:Usersmyuser.m2repository</localRepository>
...
</settings>
After fixing directories run:
- Generate Folders and Update Sources for All Projects

- Reimport all maven projects

answered Sep 16, 2020 at 9:09
Israel VareaIsrael Varea
2,5802 gold badges16 silver badges23 bronze badges
1
Tried all the above approaches, didn’t work.
Finally running maven clean install solved it!
answered Oct 4, 2017 at 10:01
Pratik NageliaPratik Nagelia
2811 gold badge4 silver badges14 bronze badges
1
Quit IntelliJ, remove every .idea directory:
rm -Rf **/.idea/
and restart.
![]()
Belphegor
4,27611 gold badges34 silver badges57 bronze badges
answered Mar 19, 2018 at 10:12
![]()
AntoineAntoine
4,1544 gold badges38 silver badges51 bronze badges
3
Invalidate Caches/ Restart and then Build -> Rebuild Project helped for me
answered Jun 25, 2018 at 8:40
1
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.
answered Jul 8, 2021 at 15:58
![]()
I got this error after I changed pom, and I fixed it by execute:
mvn idea:module
it works for me
answered Nov 23, 2021 at 1:30
Leif LiuLeif Liu
611 silver badge2 bronze badges
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)
answered May 25, 2019 at 9:35
![]()
MeirDayanMeirDayan
6205 silver badges20 bronze badges
0
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.
answered Oct 15, 2018 at 17:29
0
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.
answered Aug 17, 2020 at 5:02
![]()
Onat KorucuOnat Korucu
89411 silver badges13 bronze badges
3
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.
answered Apr 8, 2021 at 14:46
TimbuckTimbuck
1792 silver badges11 bronze badges
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.
answered Mar 12, 2018 at 14:33
Graeme MossGraeme Moss
7,7754 gold badges28 silver badges42 bronze badges
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
Andronicus
24.9k17 gold badges49 silver badges86 bronze badges
answered Aug 14, 2019 at 5:43
![]()
0
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.
answered Jun 15, 2020 at 10:36
![]()
cmlondercmlonder
2,31022 silver badges34 bronze badges
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
answered Mar 18, 2021 at 9:38
0
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)
answered Apr 28, 2020 at 12:12
![]()
DotistaDotista
3762 silver badges10 bronze badges
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.
answered Jul 22, 2021 at 17:29
![]()
Antara DattaAntara Datta
1,8892 gold badges12 silver badges16 bronze badges
2
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
answered May 26, 2020 at 18:54
barthbarth
4112 silver badges5 bronze badges
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.
answered Jun 9, 2020 at 11:27
![]()
ZhwtZhwt
4063 silver badges13 bronze badges
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.

answered Jun 16, 2020 at 19:46
cvdrcvdr
7871 gold badge10 silver badges17 bronze badges
- Demonstration of
Package Does Not Existin Java - Resolve
Package Does Not Exist Errorin Java

Today, we will reproduce the package does not exist error in Java to understand the error and its reasons. Further, we will also learn about its solution with the help of code examples.
Demonstration of Package Does Not Exist in Java
Example Code (Students.java file):
package name;
public class Students implements Comparable<Students>{
private String studentFirstName;
private String studentLastName;
public Students(String studentFirstName, String studentLastName){
this.studentFirstName = studentFirstName;
this.studentLastName = studentLastName;
}
public String getStudentFirstName() {
return studentFirstName;
}
public void setStudentFirstName(String studentFirstName) {
this.studentFirstName = studentFirstName;
}
public String getStudentLastName() {
return studentLastName;
}
public void setStudentLastName(String studentLastName) {
this.studentLastName = studentLastName;
}
/**
*
* @param other
* @return
*/
@Override
public int compareTo(Students other) {
int compareResults = this.studentLastName
.compareTo(other.studentLastName);
if(compareResults == 0){
if(this.studentFirstName.chars().count() ==
other.studentFirstName.chars().count()) {
compareResults = 0;
return compareResults;
}
else if(this.studentFirstName.chars().count() >
other.studentFirstName.chars().count()){
compareResults = 1;
return compareResults;
}
else{
compareResults = -1;
return compareResults;
}
}
else{
return compareResults;
}
}
}
Example Code (StudentMain.java file):
import names.Students;
public class StudentMain {
public static void main(String[] args) {
Students student1 = new Students ("Ali", "Ashfaq");
Students student2 = new Students ("Ali", "Ashfaq");
System.out.println("Comparison 1: " + student1.compareTo(student2));
Students student3 = new Students ("Ali", "Ashfaq");
Students student4 = new Students ("Zoya", "Ashfaq");
System.out.println("Comparison 2: " + student3.compareTo(student4));
Students student5 = new Students ("Mehr-un-nissa", "Ashfaq");
Students student6 = new Students ("Hina", "Ashfaq");
System.out.println("Comparison 3: " + student5.compareTo(student6));
}
}
We have a directory Desktop/java/stuff/com/name where all our .java files are located except those containing the main() method. For the above code example, we have Students.java in the Desktop/java/stuff/com/name directory, while StudentMain.java with the main() method is in the Desktop/java/stuff/com directory.
It is also important to note that we have set Desktop/java/stuff to our CLASSPATH.
Let’s understand the code to figure out the error and its causes.
The above code compares the last names of the Students and stores the result in the compareResults variable. This result is further used to compare their first names. How?
If the last name matches, the result would be true means 0. So, it jumps to the if condition and assesses if the number of characters in their first names matches.
The result of comparing first names is based on the following conditions:
- If
this.countis equal to theother.count, the result will be0. - If
this.countis greater than theother.count, the result will be1. - If
this.countis less than theother.count, the result will be-1.
But, when we try to compile the program, it gives us the following error.
C:UsersMEHVISH ASHIQDesktopjavastuffcom>javac StudentMain.java
StudentMain.java:1: error: package names do not exist
import names.Students;
What does it mean, and why are we facing this problem? This error means the package we are trying to import does not exist.
There can be different reasons for that, and all of them are listed below:
-
We have imported the incorrect package, or we may have some typos while importing the package.
-
Recheck if all of the files are in the correct sub-directories.
-
If we have set our
CLASSPATHtoDesktop/java/stuff, then the files defined withpackage name;must reside in theDesktop/java/stuff/com/namedirectory. You may check this to learn how to setCLASSPATH. -
Make sure all the Java source files are in the correct sub-directory. We must also ensure that the Java source files are compiled in the
Desktop/java/stuff/com/namedirectory.Why? The
.classfiles must be on theCLASSPATH. Remember, the.javafiles are not required to be on theCLASSPATHbutSOURCEPATH, while.classfiles are generated when we compile the file using thejavaccommand. -
We also get this error if we don’t use the built-in package properly. See the following code:
Example Code:
public class Test{
public static void main(String[] args){
/*
Solution: This line must be as follows:
System.out.println("Hi!");
*/
system.out.println("Hi!");
}
}
Error Description:
Test.java:3: error: package system does not exist
system.out.println("Hi!");
^
1 error
Resolve Package Does Not Exist Error in Java
Example Code (Students.java file):
package name;
public class Students implements Comparable<Students>{
private String studentFirstName;
private String studentLastName;
public Students(String studentFirstName, String studentLastName){
this.studentFirstName = studentFirstName;
this.studentLastName = studentLastName;
}
public String getStudentFirstName() {
return studentFirstName;
}
public void setStudentFirstName(String studentFirstName) {
this.studentFirstName = studentFirstName;
}
public String getStudentLastName() {
return studentLastName;
}
public void setStudentLastName(String studentLastName) {
this.studentLastName = studentLastName;
}
/**
*
* @param other
* @return
*/
@Override
public int compareTo(Students other) {
int compareResults = this.studentLastName
.compareTo(other.studentLastName);
if(compareResults == 0){
if(this.studentFirstName.chars().count() ==
other.studentFirstName.chars().count()) {
compareResults = 0;
return compareResults;
}
else if(this.studentFirstName.chars().count() >
other.studentFirstName.chars().count()){
compareResults = 1;
return compareResults;
}
else{
compareResults = -1;
return compareResults;
}
}
else{
return compareResults;
}
}
}
Example Code (StudentMain.java file):
import name.Students;
public class StudentMain {
public static void main(String[] args) {
Students student1 = new Students ("Ali", "Ashfaq");
Students student2 = new Students ("Ali", "Ashfaq");
System.out.println("Comparison 1: " + student1.compareTo(student2));
Students student3 = new Students ("Ali", "Ashfaq");
Students student4 = new Students ("Zoya", "Ashfaq");
System.out.println("Comparison 2: " + student3.compareTo(student4));
Students student5 = new Students ("Mehr-un-nissa", "Ashfaq");
Students student6 = new Students ("Hina", "Ashfaq");
System.out.println("Comparison 3: " + student5.compareTo(student6));
}
}
We got the package does not exist error because of importing the wrong package in the StudentMain.java file. We were importing as import names.Students;, while it must be import name.Students;.
You may see all the commands below, including how we set the CLASSPATH.
Output:
C:UsersMEHVISH ASHIQ>cd Desktop/java/stuff
C:UsersMEHVISH ASHIQDesktopjavastuff>set classpath=.;
C:UsersMEHVISH ASHIQDesktopjavastuff>cd com/name
C:UsersMEHVISH ASHIQDesktopjavastuffcomname>javac Students.java
C:UsersMEHVISH ASHIQDesktopjavastuffcomname>cd..
C:UsersMEHVISH ASHIQDesktopjavastuffcom>javac StudentMain.java
C:UsersMEHVISH ASHIQDesktopjavastuffcom>java StudentMain
Comparison 1: 0
Comparison 2: -1
Comparison 3: 1
Импортировал проект в Intellij IDEA под Linux, все библиотеки maven подгрузил, но при сборке проекта получаю подобные ошибки на все зависимости:
Error:(4, 38) java: package org.springframework.stereotype does not
exist
Этот же проект под Windows в Intellij IDEA работает.
В чем причина может быть? Доступы?
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.project</groupId>
<artifactId>SpringREST</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SpringREST</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I’m afraid I’m able to reproduce. Here’s a diff I applied to enunciate-sample:
diff --git a/pom.xml b/pom.xml index 332623b..ca961e8 100644 --- a/pom.xml +++ b/pom.xml @@ -36,6 +36,7 @@ <version>${enunciate.version}</version> <executions> <execution> + <phase>process-classes</phase> <goals> <goal>assemble</goal> </goals> @@ -52,6 +53,13 @@ <dependencies> <dependency> + <groupId>org.immutables</groupId> + <artifactId>value</artifactId> + <version>2.5.6</version> + <scope>provided</scope> + </dependency> + + <dependency> <groupId>com.webcohesion.enunciate</groupId> <artifactId>enunciate-core-annotations</artifactId> <version>${enunciate.version}</version> diff --git a/src/main/java/com/ifyouwannabecool/api/PersonaService.java b/src/main/java/com/ifyouwannabecool/api/PersonaService.java index a1b238d..9b4f121 100644 --- a/src/main/java/com/ifyouwannabecool/api/PersonaService.java +++ b/src/main/java/com/ifyouwannabecool/api/PersonaService.java @@ -15,6 +15,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import com.ifyouwannabecool.domain.persona.Persona; +import com.ifyouwannabecool.domain.persona.Thing; /** * The persona services is used to perform actions on the data associated with a persona. @@ -33,6 +34,10 @@ public interface PersonaService @GET Persona readPersona(@PathParam("id") String personaId); + @Path("/thing") + @GET + Thing getThing(); + @Path("/{id}.json") @GET @Produces("application/json") diff --git a/src/main/java/com/ifyouwannabecool/domain/persona/Thing.java b/src/main/java/com/ifyouwannabecool/domain/persona/Thing.java index 3aede1b..2256278 100644 --- a/src/main/java/com/ifyouwannabecool/domain/persona/Thing.java +++ b/src/main/java/com/ifyouwannabecool/domain/persona/Thing.java @@ -1,7 +1,14 @@ package com.ifyouwannabecool.domain.persona; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + /** * */ +@Value.Immutable +@JsonDeserialize(as = ImmutableThing.class) public interface Thing { + + String getName(); } diff --git a/src/main/java/com/ifyouwannabecool/impl/PersonaServiceImpl.java b/src/main/java/com/ifyouwannabecool/impl/PersonaServiceImpl.java index 72b8b7a..933edca 100644 --- a/src/main/java/com/ifyouwannabecool/impl/PersonaServiceImpl.java +++ b/src/main/java/com/ifyouwannabecool/impl/PersonaServiceImpl.java @@ -12,6 +12,7 @@ import javax.ws.rs.Path; import com.ifyouwannabecool.api.PermissionDeniedException; import com.ifyouwannabecool.api.PersonaService; import com.ifyouwannabecool.domain.persona.Persona; +import com.ifyouwannabecool.domain.persona.Thing; /** * @author Ryan Heaton @@ -28,6 +29,11 @@ public class PersonaServiceImpl implements PersonaService return persona; } + @Override + public Thing getThing() { + return null; + } + public Persona readPersonaJson() { final Persona persona = new Persona();
I had no problem with setting the scope to provided; Enunciate picked up that artifact just fine.
I did have to change my Maven phase to process-classes in order to pick up the generated immutables classes, which are generated in the compile phase, which happens after the default Enunciate phase (process-sources).
Anyway, if you can send me an alternate diff that exposes the problem, I’d be happy to re-open and look into it further.