maven中的"找不到符号"错误

Use*_*321 13 maven-plugin maven spring-boot spring-boot-maven-plugin

我在stackoverflow上看到了很多关于此的问题.但是我仍然无法知道建设项目的方式是什么问题.

我有两个春季启动项目:we-data和we-web.we-web依赖于we-data.we-data在maven上编译得很好.但是我们网络给了我上面的错误.

我们数据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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

每次我在we-web上做maven"clean compile package install"目标时我都会遇到maven错误.所有抱怨的符号都在we-data项目中.出于某种原因,它表示在we-web中找不到所有类别的we-data.但是当我将应用程序作为spring boot app运行时,一切都很好.没有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:
.
.
Run Code Online (Sandbox Code Playgroud)

我有18个jdk被STS使用.而且我还没有将we-data项目放在we-web的构建路径上.我想要通过,因为我想要产生一场战争.请帮忙.我正在对we-data进行"clean compile package install",然后在we-web上进行."更新maven项目"也没有帮助我.

Sal*_*ima 25

我一直坚持这个问题一天,终于在这里找到了根本原因和解决方案:

如果您的pom上有以下行(对于您的情况是我们数据的 pom)

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
Run Code Online (Sandbox Code Playgroud)

你应该删除这些行并改为:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
</plugin>
Run Code Online (Sandbox Code Playgroud)

M. Deinum那里得到一条线索后,我发现如果你使用的话,他编译的jar是正确的spring-boot-maven-plugin,不管怎么样,谢谢你的线索.

并且请检查这个问题:在Spring Boot项目中找不到依赖关系

我试过用这个:

    <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>
Run Code Online (Sandbox Code Playgroud)

它就像一个魅力.


dav*_*xxx 4

每次我在 we-web 上执行 Maven“干净编译包安装”目标时,都会收到 Maven 错误。该抱怨未找到的所有符号都在我们的数据项目中。

1)我认为你应该阅读关于 Maven pom这里Maven 中的生命周期 的介绍。

mvn clean compile package install
Run Code Online (Sandbox Code Playgroud)

对于编译和打包阶段来说是多余的,因为安装阶段包括这些阶段(。因此,仅执行此操作:

mvn clean install
Run Code Online (Sandbox Code Playgroud)

2) 运行 Maven 目标的 Web 模块需要com.we:data:0.0.1-SNAPSHOT与实际代码的依赖关系:

    <dependency>
        <groupId>com.we</groupId>
        <artifactId>data</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

如果您添加或修改代码并且未安装此模块,则 Web 模块将无法看到这些更改。

因此,您应该 先mvn clean installcom.we:data模块中执行此操作,然后再在 Web 模块中执行此操作。

最后,避免具有未更新的依赖关系的最简单方法是mvn clean install从聚合这些模块的多模块项目运行。