mvn安装错误:软件包不存在

时间:2020-01-15 00:25:28

标签: java spring-boot maven

我有这种情况:

  1. 我有一个带有Spring Boot的Maven项目,其中在该包结构中只有一些典型的pojo类,例如:com.demo.core

pom结构

    <properties>
        <java.version>1.8</java.version>
    </properties>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </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>

com / demo / core / Person.java

  1. 然后我试图将该基础项目用作负责数据库持久性的其他spring boot项目的依赖项。

    • 在这里我使用spring数据,lombok等。

第二个项目pom依赖项:

<properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derby</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!--  local dependencies -->
**
        <dependency>
            <groupId>com.demo</groupId>
            <artifactId>core-baseproject</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency> 
**
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
  1. 我在基础项目中运行mvn clean install并验证jar文件位于我的本地.m2存储库结构中。

  2. 当我尝试在第二个项目中运行mvn clean install时,出现错误,指出com.demo.core软件包未退出,因此未在该软件包中找到类。

    < / li>

错误详细信息:

[INFO] Scanning for projects...
[INFO] 
[INFO] --------------< com.demo:jpa-dataprovider-simple >---------------
[INFO] Building jpa-dataprovider-simple 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ jpa-dataprovider-simple ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ jpa-dataprovider-simple ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to /home/demo/sts-eclipse-wrkspace-simple/jpa-dataprovider-simple/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/demo/sts-eclipse-wrkspace-simple-pos/jpa-dataprovider-simple-pos/src/main/java/com/demo/jpa/dataprovider/mapper/TerminalConfigJpaMapper.java:[4,35] package com.demo.core.entity does not exist
[ERROR] /home/demo/sts-eclipse-wrkspace-simple-pos/jpa-dataprovider-simple/src/main/java/com/demo/jpa/dataprovider/mapper/TerminalConfigJpaMapper.java:[8,59] cannot find symbol
  symbol:   class TerminalConfig
  location: class com.demo.jpa.dataprovider.mapper.TerminalConfigJpaMapper
[ERROR] /home/demo/sts-eclipse-wrkspace-simple-pos/jpa-dataprovider-simple/src/main/java/com/demo/jpa/dataprovider/mapper/TerminalConfigJpaMapper.java:[18,23] cannot find symbol
  symbol:   class TerminalConfig
  location: class com.demo.jpa.dataprovider.mapper.TerminalConfigJpaMapper
[ERROR] /home/demo/sts-eclipse-wrkspace-simple-pos/jpa-dataprovider-simple/src/main/java/com/demo/jpa/dataprovider/gateway/JpaTerminalConfigGatewayImpl.java:[9,35] package com.demo.core.entity does not exist
[ERROR] /home/demo/sts-eclipse-wrkspace-simple-pos/jpa-dataprovider-simple/src/main/java/com/demo/jpa/dataprovider/gateway/JpaTerminalConfigGatewayImpl.java:[10,36] package com.demo.core.gateway does not exist
[ERROR] /home/demo/sts-eclipse-wrkspace-simple-pos/jpa-dataprovider-simple/src/main/java/com/demo/jpa/dataprovider/gateway/JpaTerminalConfigGatewayImpl.java:[14,54] cannot find symbol
  symbol: class TerminalConfigGateway
[ERROR] /home/demo/sts-eclipse-wrkspace-simple/jpa-dataprovider-simple/src/main/java/com/demo/jpa/dataprovider/gateway/JpaTerminalConfigGatewayImpl.java:[24,36] cannot find symbol
  symbol:   class TerminalConfig
  location: class com.demo.jpa.dataprovider.gateway.JpaTerminalConfigGatewayImpl
[ERROR] /home/demo/sts-eclipse-wrkspace-simple-pos/jpa-dataprovider-simple/src/main/java/com/demo/jpa/dataprovider/gateway/JpaTerminalConfigGatewayImpl.java:[24,16] cannot find symbol
  symbol:   class TerminalConfig
  location: class com.demo.jpa.dataprovider.gateway.JpaTerminalConfigGatewayImpl
[INFO] 8 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.714 s
[INFO] Finished at: 2020-01-14T18:08:20-05:00
[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.8.1:compile (default-compile) on project jpa-dataprovider-simple: Compilation failure: Compilation failure: 
[ERROR] /home/demo/sts-eclipse-wrkspace-simple/jpa-dataprovider-simple/src/main/java/com/d/jpa/dataprovider/mapper/TerminalConfigJpaMapper.java:[4,35] package com.demo.core.entity does not exist
[ERROR] /home/demo/sts-eclipse-wrkspace-simple/jpa-dataprovider-simple/src/main/java/com/demo/jpa/dataprovider/mapper/TerminalConfigJpaMapper.java:[8,59] cannot find symbol
[ERROR]   symbol:   class TerminalConfig
[ERROR]   location: class com.demo.jpa.dataprovider.mapper.TerminalConfigJpaMapper
[ERROR] /home/demo/sts-eclipse-wrkspace-simple/jpa-dataprovider-simple/src/main/java/com/demo/jpa/dataprovider/mapper/TerminalConfigJpaMapper.java:[18,23] cannot find symbol
[ERROR]   symbol:   class TerminalConfig
[ERROR]   location: class com.demo.jpa.dataprovider.mapper.TerminalConfigJpaMapper
[ERROR] /home/demo/sts-eclipse-wrkspace-simple/jpa-dataprovider-simple/src/main/java/com/demo/jpa/dataprovider/gateway/JpaTerminalConfigGatewayImpl.java:[9,35] package com.demo.core.entity does not exist
[ERROR] /home/demo/sts-eclipse-wrkspace-simple/jpa-dataprovider-simple/src/main/java/com/demo/jpa/dataprovider/gateway/JpaTerminalConfigGatewayImpl.java:[10,36] package com.demo.core.gateway does not exist
[ERROR] /home/demo/sts-eclipse-wrkspace-simple/jpa-dataprovider-simple/src/main/java/com/demo/jpa/dataprovider/gateway/JpaTerminalConfigGatewayImpl.java:[14,54] cannot find symbol
[ERROR]   symbol: class TerminalConfigGateway
[ERROR] /home/demo/sts-eclipse-wrkspace-simple/jpa-dataprovider-simple/src/main/java/com/demo/jpa/dataprovider/gateway/JpaTerminalConfigGatewayImpl.java:[24,36] cannot find symbol
[ERROR]   symbol:   class TerminalConfig
[ERROR]   location: class com.demo.jpa.dataprovider.gateway.JpaTerminalConfigGatewayImpl
[ERROR] /home/demo/sts-eclipse-wrkspace-simple/jpa-dataprovider-simple/src/main/java/com/demo/jpa/dataprovider/gateway/JpaTerminalConfigGatewayImpl.java:[24,16] cannot find symbol
[ERROR]   symbol:   class TerminalConfig
[ERROR]   location: class com.demo.jpa.dataprovider.gateway.JpaTerminalConfigGatewayImpl
[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

有人知道如何解决这个问题吗?

我正在使用:

Spring Tool Suite 4 版本:4.5.0.RELEASE

java-8-openjdk-amd64

maven 3.6.0

springboot版本2.1.11 预先感谢。

对我来说,有些新东西,当我在jar文件中查看时,结构是这样的:

Jar structure generated by spring boot

由于某种原因,我将eclipse中的maven配置更改为使用已安装的而不是embedbeb的,但是现在我收到此错误。

[错误]测试运行:1,失败:0,错误:1,跳过:0,经过的时间:1.619 s <<<失败! -在com.oxypora.jpa.dataprovider.JpaDataproviderSimplePosApplicationTests中 [错误] contextLoads(com.oxypora.jpa.dataprovider.JpaDataproviderSimplePosApplicationTests)经过的时间:0.015 s <<<错误! java.lang.IllegalStateException:无法加载ApplicationContext 原因:org.springframework.beans.factory.BeanDefinitionStoreException:无法解析配置类[com.oxypora.jpa.dataprovider.JpaDataproviderSimplePosApplication];嵌套异常是java.io.FileNotFoundException:类路径资源[com / oxypora / pos / core / gateway / TerminalConfigGateway.class]无法打开,因为它不存在 原因:java.io.FileNotFoundException:类路径资源[com / oxypora / pos / core / gateway / TerminalConfigGateway.class]无法打开,因为它不存在

2 个答案:

答案 0 :(得分:2)

当您有两个或多个springboot项目并且想要将它们作为其他项目的依赖项进行连接时,我找到了另一种解决方案。

解决方案不是使用spring-boot-maven-plugin,此插件会覆盖jar的常规包,从而导致您的类和包结构在BOOT-INF / classes下移动。

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

enter image description here

答案 1 :(得分:1)

我解决了这个问题,springboot项目生成了一个在metainf文件中配置的不同jar结构,这样就不会在典型文件夹中添加类。

我所做的就是将核心项目更改为一个简单的maven项目,而没有春季启动的复杂性,现在第二个项目(春季启动一个)的编译没有问题。

不需要将基础项目作为springboot项目。