Error "cannot find character" in maven

I see a lot of questions about stackoverflow. But still I can’t understand what the problem is in my way of creating projects.

I have two spring boot projects: we-data and we-web. we-web depends on we data. we-data are compiled on maven. But we-web gives me the error above.

we-data pom:

<?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.we</groupId> <artifactId>data</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>we-data</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.2.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 

we-web pom:

 <?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.we</groupId> <artifactId>web</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>we-web</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.2.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <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>com.we</groupId> <artifactId>data</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> 

Every time I do maven "clean compile installation package" on we-web, I get a maven error. All the characters that complains are not found, we are all in the data project. For some reason, he says that all we data classes cannot be found on we-web. But when I run the application as a spring boot application, everything is fine. There is no maven error for this:

 [INFO] ------------------------------------------------------------------------ [INFO] Building we-web 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ web --- [INFO] Deleting C:\Users\user\Documents\GitHub\we\we-web\target [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ web --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ web --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 10 source files to C:\Users\user\Documents\GitHub\we\we-web\target\classes [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /C:/Users/user/Documents/GitHub/we/we-web/src/main/java/com/we/controller/EmployeeController.java:[13,25] package com.we.service does not exist [ERROR] /C:/Users/user/Documents/GitHub/we/we-web/src/main/java/com/we/controller/EmployeePaymentController.java:[22,9] cannot find symbol symbol: class EmployeeService location: class com.we.controller.EmployeePaymentController . . . [INFO] 44 errors [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3.322 s [INFO] Finished at: 2016-12-26T15:30:54+05:30 [INFO] Final Memory: 26M/253M [INFO] ------------------------------------------------------------------------ [WARNING] The requested profile "pom.xml" could not be activated because it does not exist. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project web: Compilation failure: Compilation failure: . . 

I have a 1.8 jdk used by STS. And also I did not put the we-data project on the build path for we-web. I want this to go away because I want to spawn a war. Please help. I do a “clean compilation package build” on we data and then do it on we-web. "Update maven project" also does not help me.

+5
source share
3 answers

I also found this problem during the day and finally found the reason and solution here, what I did:

if you have the following lines on your pom (for your case it is we-data strong> pom)

  <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> 

you must remove these lines and change to:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> </plugin> 

got the key from M. Deinum I found that it fixed the jar compilation, it won’t be a normal jar if you use spring-boot-maven-plugin , thanks for the help anyway.

and also please check this question: Dependency not found in Spring boot project

I tried using this:

  <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> <configuration> <classifier>exec</classifier> </configuration> </execution> </executions> </plugin> 

It works like a charm.

+11
source

Every time I do maven "clean build packages", the goal on the we-web is I get a maven error. All characters that complains about this are not found; all in the "data" project.

1) I think you should read the introduction about Maven pom here and the life cycle in Maven .

 mvn clean compile package install 

is redundant for the compilation and packaging phases, since the installation phase includes these steps (. So, do this only:

 mvn clean install 

2) Your web module on which you run the maven target requires com.we:data:0.0.1-SNAPSHOT to com.we:data:0.0.1-SNAPSHOT on your actual code:

  <dependency> <groupId>com.we</groupId> <artifactId>data</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> 

If you add or modify code and do not install this module, the web module cannot see these changes.

So you have to do mvn clean install in the com.we:data module before doing this in the web module.

Finally, the simplest way to avoid having an mvn clean install dependency is mvn clean install from a multi-module project that integrates these modules.

+2
source

In pom.xml add depedency

 <dependency> <groupId>javax.inject</groupId> <artifactId>javax.inject</artifactId> <version>1</version> </dependency> 

and the class in which you use @Inject Import javax.inject.Inject import javax.inject.Inject ;

0
source

Source: https://habr.com/ru/post/1261898/


All Articles