首页 > 解决方案 > 对一个项目进行任何更改后,Maven 编译错误“找不到符号”

问题描述

好吧,我在同一时间用 maven 学习 JEE:p 我在 netbeans -> core ->frontoffice 中有这种项目结构

frontoffice 使用来自核心的类,所以我在 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.directmedia.onlinestore</groupId>
    <artifactId>frontoffice</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>

    <name>frontoffice</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>m.directmedia.onlinestore</groupId>
            <artifactId>core</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

核心项目 pom.xml 没有变化。一切正常我可以在前台使用核心项目的类,但是当我向核心类添加一些东西并清理和构建时。好的,但是当我在前台项目上清理和构建时,我得到了我添加的错误:

-------------------------------------------------------------
com/directmedia/onlinestore/controller/CatalogueServlet.java:[79,15] cannot find symbol
  symbol:   variable aa
  location: variable titre1 of type com.directmedia.onlinestore.core.entity.Work
com/directmedia/onlinestore/controller/CatalogueServlet.java:[80,15] cannot find symbol
  symbol:   variable aa
  location: variable titre2 of type com.directmedia.onlinestore.core.entity.Work
com/directmedia/onlinestore/controller/CatalogueServlet.java:[81,15] cannot find symbol
  symbol:   variable aa
  location: variable titre3 of type com.directmedia.onlinestore.core.entity.Work
com/directmedia/onlinestore/controller/CatalogueServlet.java:[101,27] cannot find symbol
  symbol:   variable aa
  location: variable oeuvre of type com.directmedia.onlinestore.core.entity.Work
4 errors 
-------------------------------------------------------------
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 2.899 s
Finished at: 2019-10-14T22:19:21+02:00
Final Memory: 17M/196M
------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project frontoffice: Compilation failure: Compilation failure:
com/directmedia/onlinestore/controller/CatalogueServlet.java:[79,15] cannot find symbol
symbol:   variable aa
location: variable titre1 of type com.directmedia.onlinestore.core.entity.Work
com/directmedia/onlinestore/controller/CatalogueServlet.java:[80,15] cannot find symbol
symbol:   variable aa
location: variable titre2 of type com.directmedia.onlinestore.core.entity.Work
com/directmedia/onlinestore/controller/CatalogueServlet.java:[81,15] cannot find symbol
symbol:   variable aa
location: variable titre3 of type com.directmedia.onlinestore.core.entity.Work
com/directmedia/onlinestore/controller/CatalogueServlet.java:[101,27] cannot find symbol
symbol:   variable aa
location: variable oeuvre of type com.directmedia.onlinestore.core.entity.Work
-> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

就像旧版本的类仍然存在,编译器编译它们而不是修改过的类。我试图清理项目和netbeans缓存,但同样的错误我不知道为什么会发生这种情况在我看来不合逻辑。

你能帮我找出问题所在吗?

要查看我的代码并测试这里是存储库:https ://github.com/AmineJonahi/jee.maven

标签: javamavennetbeanspom.xml

解决方案


推荐阅读