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

问题描述 投票:0回答:2

我有一个spring boot项目Proj-Main和另一个包含名为Proj-Entities的实体类的项目。这两种都存在于本地。我已将后者添加为第一个的依赖项。它在我的IDE(在我的情况下是STS)中完美地工作,但是当我尝试使用mvn package创建一个jar来部署到服务器,甚至mvn installProj-Main时,它无法找到Proj-Entities中存在的类。我检查了我的.m2目录,我能够在那里找到Proj-Entities的罐子。我已经尝试过标准的清洁和重建技术,但它似乎没有用。

这是我添加依赖的方式:

    <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>
java maven spring-boot maven-2 maven-3
2个回答
0
投票

在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


0
投票

通过在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>
© www.soinside.com 2019 - 2024. All rights reserved.