【问题标题】:Maven : Package not found when clean installMaven:全新安装时找不到包
【发布时间】:2020-10-04 23:12:38
【问题描述】:

我在 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 类路径(源附件)。所以我通过 Build path > jar > added source attachment 添加。但我仍然得到相同的编译错误。

【问题讨论】:

  • 你需要添加你的外部jar作为编译时间&lt;dependency&gt;
  • 怎么样?你能告诉我吗?
  • 你可以google 'add maven dependency' 有多个资源
  • and I added only through Build path.. 是什么意思?请显示完整的 pom 文件

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


【解决方案1】:

在 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>
  1. 在 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>

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-23
    • 2021-08-01
    • 1970-01-01
    • 2012-08-27
    • 2022-12-10
    • 2019-07-21
    • 2013-08-30
    相关资源
    最近更新 更多