【问题标题】:cannot find symbol: Package not recognized找不到符号:无法识别包裹
【发布时间】:2020-07-03 00:06:53
【问题描述】:

我无法编译这个项目,即使做了所有必要的配置,但不幸的是没有成功。

我成功编译了第一个exchange-core!使用此命令:

mvn install

这是另一个项目工作的必需依赖项。

之后,我到了目标文件夹,并启动了这个命令:

mvn install:install-file -Dfile=exchange-core-0.5.4-SNAPSHOT.jar -DgroupId=exchange.core2 -DartifactId=exchange-core -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar -DgeneratePom=true

所以我可以让其他项目可以访问依赖项。

但是在尝试编译网关(将使用第一次编译的项目)时,我收到了这个错误!

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Exchange REST Gateway 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ exchange-gateway-rest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 9 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ exchange-gateway-rest ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 62 source files to /build/exchange-gateway/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /build/exchange-gateway/src/main/java/exchange/core2/rest/controllers/SyncTradeMiscApiController.java:[26,33] package org.jetbrains.annotations does not exist
[ERROR] /build/exchange-gateway/src/main/java/exchange/core2/rest/RestGatewayApplication.java:[20,37] cannot find symbol
  symbol:   class OrderBookFastImpl
  location: package exchange.core2.core.orderbook
[ERROR] /build/exchange-gateway/src/main/java/exchange/core2/rest/RestGatewayApplication.java:[21,50] package exchange.core2.core.processors.journalling do
es not exist
[ERROR] /build/exchange-gateway/src/main/java/exchange/core2/rest/RestGatewayApplication.java:[31,52] cannot find symbol
  symbol:   class ThreadAffinityMode
  location: class exchange.core2.core.utils.UnsafeUtils
[ERROR] /build/exchange-gateway/src/main/java/exchange/core2/rest/RestGatewayApplication.java:[31,1] static import only from classes and interfaces
[ERROR] /build/exchange-gateway/src/main/java/exchange/core2/rest/controllers/SyncTradeMiscApiController.java:[64,6] cannot find symbol
  symbol:   class NotNull
  location: class exchange.core2.rest.controllers.SyncTradeMiscApiController
[INFO] 6 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.359 s
[INFO] Finished at: 2020-07-02T20:13:06Z
[INFO] Final Memory: 35M/85M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project exchange-gateway-rest: Compilation
 failure: Compilation failure:
[ERROR] /build/exchange-gateway/src/main/java/exchange/core2/rest/controllers/SyncTradeMiscApiController.java:[26,33] package org.jetbrains.annotations doe
s not exist
[ERROR] /build/exchange-gateway/src/main/java/exchange/core2/rest/RestGatewayApplication.java:[20,37] cannot find symbol
[ERROR]   symbol:   class OrderBookFastImpl
[ERROR]   location: package exchange.core2.core.orderbook
[ERROR] /build/exchange-gateway/src/main/java/exchange/core2/rest/RestGatewayApplication.java:[21,50] package exchange.core2.core.processors.journalling do
es not exist
[ERROR] /build/exchange-gateway/src/main/java/exchange/core2/rest/RestGatewayApplication.java:[31,52] cannot find symbol
[ERROR]   symbol:   class ThreadAffinityMode
[ERROR]   location: class exchange.core2.core.utils.UnsafeUtils
[ERROR] /build/exchange-gateway/src/main/java/exchange/core2/rest/RestGatewayApplication.java:[31,1] static import only from classes and interfaces
[ERROR] /build/exchange-gateway/src/main/java/exchange/core2/rest/controllers/SyncTradeMiscApiController.java:[64,6] cannot find symbol
[ERROR]   symbol:   class NotNull
[ERROR]   location: class exchange.core2.rest.controllers.SyncTradeMiscApiController
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

这个错误:

package org.jetbrains.annotations does not exist

我认为可以通过添加 jetbrains 依赖项或从文件中删除它来解决。

但是其他的呢:

cannot find symbol
[ERROR]   symbol:   class OrderBookFastImpl
[ERROR]   location: package exchange.core2.core.orderbook

知道这个依赖来自第一个项目。

我正在使用带有图像的 docker:maven:3.5.2-jdk-8-alpine

github上的项目

项目 1(交换核心):https://github.com/mzheravin/exchange-core

项目 2(交换网关):https://github.com/exchange-core/exchange-gateway-rest

第二个项目的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>exchange.core2</groupId>
    <artifactId>exchange-gateway-rest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Exchange REST Gateway</name>
    <description>Java Exchange Market Gateway</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath/>
    </parent>

    <properties>
        <skip.it>false</skip.it>

        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>

        <guava.version>25.0-jre</guava.version>
        <commons-math3.version>3.6.1</commons-math3.version>
        <commons-lang3.version>3.7</commons-lang3.version>

        <HikariCP.version>3.1.0</HikariCP.version>

        <eclipse.collections.version>9.2.0</eclipse.collections.version>
    </properties>

    <dependencyManagement>
        <dependencies>

            <dependency>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>${guava.version}</version>
            </dependency>

            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>${commons-lang3.version}</version>
            </dependency>

            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-math3</artifactId>
                <version>${commons-math3.version}</version>
            </dependency>

            <!-- Eclipse (Goldman Sachs) collections -->
            <dependency>
                <groupId>org.eclipse.collections</groupId>
                <artifactId>eclipse-collections-api</artifactId>
                <version>9.2.0</version>
            </dependency>
            <dependency>
                <groupId>org.eclipse.collections</groupId>
                <artifactId>eclipse-collections</artifactId>
                <version>9.2.0</version>
            </dependency>

        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>exchange.core2</groupId>
            <artifactId>exchange-core</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>webjars-locator-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>sockjs-client</artifactId>
            <version>1.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>stomp-websocket</artifactId>
            <version>2.3.3</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>3.3.7</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>3.1.0</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.8</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <!-- DATABASE PERSISTENCE -->
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.tomcat</groupId>
                    <artifactId>tomcat-jdbc</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-java8</artifactId>
        </dependency>
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <version>${HikariCP.version}</version>
        </dependency>

        <!-- Eclipse (Goldman Sachs) collections -->
        <dependency>
            <groupId>org.eclipse.collections</groupId>
            <artifactId>eclipse-collections-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.eclipse.collections</groupId>
            <artifactId>eclipse-collections</artifactId>
        </dependency>

        <!-- tests -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <profiles>
        <profile>
            <id>default</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>it</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration combine.self="override">
                            <!--<argLine>-XX:+PrintApplicationStoppedTime</argLine>-->
                            <redirectTestOutputToFile>true</redirectTestOutputToFile>
                            <includes>
                                <include>**/IT*.java</include>
                                <include>**/*IntegrationTest.java</include>
                            </includes>
                            <excludes>
                                <exclude>**/remote/**/*.class</exclude>
                                <exclude>**/stress/**/*.class</exclude>
                                <exclude>**/*Remote*Test.java</exclude>
                                <exclude>**/*Stress*Test.java</exclude>
                            </excludes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>

我们从这行调用本地依赖:

    <dependency>
        <groupId>exchange.core2</groupId>
        <artifactId>exchange-core</artifactId>
        <version>0.5.4-SNAPSHOT</version> //<-- changed the version here to the current one
    </dependency>

【问题讨论】:

    标签: java spring docker maven


    【解决方案1】:

    我克隆了你的 git 存储库。
    您的 exchange-core 项目中没有 OrderBookFastImpl 类。

    【讨论】:

    • 好像是用旧版的,谢谢!
    【解决方案2】:

    看看这个:在mvn install:install-file 命令中你写了version=0.0.1-SNAPSHOT,而在pom.xml 我看到&lt;version&gt;0.5.4-SNAPSHOT&lt;/version&gt;

    【讨论】:

    • 我已经这样做了,但不幸的是再次收到同样的错误!你对这个问题有其他想法吗?谢谢!
    猜你喜欢
    • 2013-08-20
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 2016-11-28
    • 1970-01-01
    • 2021-03-22
    • 2020-05-31
    • 1970-01-01
    相关资源
    最近更新 更多