I've been working on a bigger project for about a month now. It is a multi-module maven/java project. So far, I've had this "error" several times, but I've successfully resolved it after trying to launch the app a few times. Until now, I thought it was a bug in my IntelliJ Idea. Yesterday, the same problem happened to me again, and no matter how many times I tried to start the application, the same error happened to me again and again.
An error occurs when building the application:
This is the first error line I see:
package com.marketcruiser.common.entity does not exist
When I expand the error:
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ market-cruiser-back-end ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 23 source files to D:\programiranje\JAVA\Spring Projects\market-cruiser-project\market-cruiser-web-parent\market-cruiser-back-end\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /D:/programiranje/JAVA/Spring Projects/market-cruiser-project/market-cruiser-web-parent/market-cruiser-back-end/src/main/java/com/marketcruiser/admin/user/UserServiceImpl.java:[3,39] package com.marketcruiser.common.entity does not exist
[ERROR] /D:/programiranje/JAVA/Spring Projects/market-cruiser-project/market-cruiser-web-parent/market-cruiser-back-end/src/main/java/com/marketcruiser/admin/user/UserServiceImpl.java:[4,39] package com.marketcruiser.common.entity does not exist
[ERROR] /D:/programiranje/JAVA/Spring Projects/market-cruiser-project/market-cruiser-web-parent/market-cruiser-back-end/src/main/java/com/marketcruiser/admin/user/UserService.java:[3,39] package com.marketcruiser.common.entity does not exist
[ERROR] /D:/programiranje/JAVA/Spring Projects/market-cruiser-project/market-cruiser-web-parent/market-cruiser-back-end/src/main/java/com/marketcruiser/admin/user/UserService.java:[4,39] package com.marketcruiser.common.entity does not exist
[ERROR] /D:/programiranje/JAVA/Spring Projects/market-cruiser-project/market-cruiser-web-parent/market-cruiser-back-end/src/main/java/com/marketcruiser/admin/user/UserRepository.java:[3,39] package com.marketcruiser.common.entity does not exist
[ERROR] /D:/programiranje/JAVA/Spring Projects/market-cruiser-project/market-cruiser-web-parent/market-cruiser-back-end/src/main/java/com/marketcruiser/admin/user/UserRepository.java:[11,55] cannot find symbol
symbol: class User
[ERROR] /D:/programiranje/JAVA/Spring Projects/market-cruiser-project/market-cruiser-web-parent/market-cruiser-back-end/src/main/java/com/marketcruiser/admin/user/RoleRepository.java:[3,39] package com.marketcruiser.common.entity does not exist
[ERROR] /D:/programiranje/JAVA/Spring Projects/market-cruiser-project/market-cruiser-web-parent/market-cruiser-back-end/src/main/java/com/marketcruiser/admin/user/RoleRepository.java:[8,55] cannot find symbol
symbol: class Role
[ERROR] /D:/programiranje/JAVA/Spring Projects/market-cruiser-project/market-cruiser-web-parent/market-cruiser-back-end/src/main/java/com/marketcruiser/admin/user/UserServiceImpl.java:[37,12] cannot find symbol
More than 100 lines of such error codes.
Architecture of my project is:
market-cruiser-project -> market-cruiser-common
-> market-cruiser-web-parent -> market-cruiser-back-end
-> market-cruiser-front-end
This is pom.xml of market-cruiser-project
:
<?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.marketcruiser</groupId>
<artifactId>market-cruiser-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>market-cruiser-project</name>
<description>Root project</description>
<modules>
<module>market-cruiser-common</module>
<module>market-cruiser-web-parent</module>
</modules>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
</project>
pom.xml of market-cruiser-common
:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.marketcruiser</groupId>
<artifactId>market-cruiser-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>market-cruiser-common</name>
<description>common library</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
pom.xml of market-cruiser-web-parent
:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.marketcruiser</groupId>
<artifactId>market-cruiser-web-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>market-cruiser-web-parent</name>
<description>parent spring web project</description>
<properties>
<java.version>17</java.version>
</properties>
<modules>
<module>market-cruiser-back-end</module>
<module>market-cruiser-front-end</module>
</modules>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator-core</artifactId>
</dependency>
<dependency>
<groupId>com.marketcruiser</groupId>
<artifactId>market-cruiser-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
pom.xml of market-cruiser-back-end
:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.marketcruiser</groupId>
<artifactId>market-cruiser-web-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>market-cruiser-back-end</artifactId>
<name>market-cruiser-back-end</name>
<description>market cruiser admin project</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>net.sf.supercsv</groupId>
<artifactId>super-csv</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>com.github.librepdf</groupId>
<artifactId>openpdf</artifactId>
<version>1.3.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
And pom.xml of market-cruiser-front-end
:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.marketcruiser</groupId>
<artifactId>market-cruiser-web-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>market-cruiser-front-end</artifactId>
<name>market-cruiser-front-end</name>
<description>market-cruiser-front-end</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
</project>
Does anyone have an idea how to fix this problem?
What I tried to do in order to resolve the issue:
- I used
@EntityScan({"com.marketcruiser.common.entity", "com.marketcruiser.admin.user"})
in my SpringBootApplication - I updated pom.xml to java version installed on my PC.
- I tried to rebuild the app several times.
CodePudding user response:
In your current setup, market-cruiser-common
and market-cruiser-web-parent
are two fully separate projects that don't have anything in common. Your current structure is not what you think it is, but instead this:
market-cruiser-project
market-cruiser-common
market-cruiser-web-parent -> market-cruiser-back-end
-> market-cruiser-front-end
market-cruiser-common
and market-cruiser-web-parent
should use market-cruiser-project
as parent, not spring-boot-starter-parent
. That should instead be the parent of market-cruiser-project
. Then you get the structure you want.