java - Maven : Package not found when clean install

标签 java spring-boot maven maven-2 executable-jar

我的 Spring Boot 项目。我的项目中有一个外部 jar 文件,并且仅通过构建路径添加。当我使用 Maven clean install 命令运行我的项目时。我收到以下错误消息:

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /D:/Code/workspace/NestOrion/src/main/java/orion/trader/individual/IndividualOrderTrader.java:[16,33] package com.omnesys.nestq.classes does not exist
[ERROR] /D:/Code/workspace/NestOrion/src/main/java/orion/trader/individual/IndividualOrderTrader.java:[17,33] package com.omnesys.nestq.classes does not exist
[ERROR] /D:/Code/workspace/NestOrion/src/main/java/orion/trader/individual/IndividualOrderTrader.java:[36,28] cannot find symbol

Pom.xml:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <classifier>exec</classifier>
                        <mainClass>
                            com.orion.main.NestOrionApplication
                        </mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>

我也阅读了其他文章,有时在运行时找不到外部 jar 文件路径,因此我们需要 java 类路径(源附件)。所以我通过“构建路径”>“jar”>“添加源附件”添加。但我仍然遇到相同的编译错误。

最佳答案

在 Maven 依赖项中添加外部 jar 后,它解决了我的问题。

步骤:

  1. 在项目中创建 libs 文件夹。右键单击项目>新建>文件夹>库
  2. 将外部 jar 文件放入该文件夹中。
  3. 打开 pom.xml 文件并将该依赖项添加到您的代码中。

jar 名称:ReleaseVersion.jar

    <dependency>
        <groupId>DealerNestQApiReleaseVersion</groupId>
        <artifactId>DealerNestQApiReleaseVersion</artifactId>
        <scope>system</scope>
        <version>1.1</version>
        <systemPath>${basedir}/libs/DealerNestQApiReleaseVersion.jar</systemPath>
    </dependency>
  • 在maven中添加以下代码。
  •     <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    通过使用此步骤,我解决了我的问题。

    关于java - Maven : Package not found when clean install,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62389951/

    相关文章:

    java - web.xml : "No grammar constraints (DTD or XML schema) detected for the document." 的虚假 Eclipse 警告

    java - 自定义共享意向对话框这可能吗?

    Spring Jpa 规范和预加载

    java - 永久内存不足 | java |智能

    java - 如何在Java中将字符串日期转换为时间戳,格式为dd-MMM-yyyy?

    java - 如何在运行时设置通用Java类的类型?

    java - 使用 @DateTimeFormat 的日期时间解析问题

    java - 在 Spring-Boot 中从 websocket 接收数据时调用服务时遇到问题

    java - Maven 忽略了 maven archiver

    java - Maven 和 java : missing generated code for service in test directory