mvn install 或 package 失败,因为无法从工作区中的另一个包中找到符号

mvn install or package fails because unable to find symbols from another package in workspace

我有一个 spring 引导项目 Proj-Main 和另一个包含名为 Proj-Entities 的实体 类 的项目。这两者都存在于本地。我将后者添加为第一个的依赖项。它在我的 IDE(在我的例子中是 STS)中完美运行,但是当我尝试创建一个 jar 以使用 mvn package 甚至 mvn install 用于 Proj-Main 部署到服务器时,它失败了找到 Proj-Entities 中的 类。我已经检查了我的 .m2 目录,我可以在那里找到 Proj-Entities 的 jar。我已经尝试过标准的清理和重建技​​术,但它似乎不起作用。

这就是我添加依赖项的方式:

    <dependency>
        <groupId>com.proj</groupId>
        <artifactId>Proj-Entities</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>

我的构建任务如下所示:

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

在 rout proj-main 中添加模块部分。在模块部分添加

<module>../Proj-Entities</module>

然后在您的 Proj-Main 中执行 "mvn clean install"。您将在目标文件夹中获得一个 war 文件和一个 jar 文件。

或者你可以试试这个

<dependency>
     <groupId>com.proj</groupId>
     <artifactId>Proj-Entities</artifactId>
     <version>0.0.1-SNAPSHOT</version>
     <scope>system</scope>
     <systemPath>${basedir}/lib/Proj-Entities-1.0.0.jar</systemPath>
</dependency>

您可以根据您的项目指定您的jar 文件名。

"systemPath" here, it requires the absolute path of the project.You can make it easier by keeping the file inside the project itself such that "basedir" will work

通过将以下构建目标添加到 Proj-Entities pom 中解决了这个问题。

<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>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>