gpt4 book ai didi

maven - Maven 中的 "cannot find symbol"错误

转载 作者:行者123 更新时间:2023-12-03 21:14:31 25 4
gpt4 key购买 nike

我看到很多关于stackoverflow的问题。但是我仍然无法知道我构建项目的方式有什么问题。

我有两个 Spring Boot 项目:we-data 和 we-web。 we-web 依赖于我们的数据。 we-data 在 maven 上编译得很好。但是 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>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>

每次我在 web 上执行 maven“clean compile package install”目标时,我都会收到 maven 错误。没有找到这个提示的所有符号都在我们数据项目中。出于某种原因,它说在 we-web 中找不到所有类的 we-data。但是当我将应用程序作为 Spring Boot 应用程序运行时,一切都很好。没有 Maven 错误与此有关。:
[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:
.
.

我有 STS 使用的 1.8 jdk。而且我还没有将我们数据项目放在我们网络的构建路径上。我想让这一切过去,因为我想引发一场 war 。请帮忙。我正在对我们的数据进行“干净的编译包安装”,然后在我们的网络上进行。 “更新 Maven 项目”也没有帮助我。

最佳答案

我也被这个问题困了一天,终于在这里找到了我所做的根本原因和解决方案:

如果你的 pom 上有以下几行(对于你的情况是 we-data 的 pom)

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

您应该删除这些行并更改为:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>

M. Deinum得到线索后我发现他是正确的,如果你使用 spring-boot-maven-plugin,编译的 jar 不会是一个普通的 jar。 ,无论如何感谢您的线索。

也请检查这个问题: Dependency not found in Spring Boot project

我试过用这个:
    <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>

它就像一个魅力。

关于maven - Maven 中的 "cannot find symbol"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41329851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com