Java maven的编译错误
我的一个项目中有一个编译错误 未能执行目标org.apache.maven.plugins:maven编译器plugin:3.1:compile 因为它找不到我已经使用的另一个项目中的所有类Java maven的编译错误,java,spring,maven,spring-mvc,spring-boot,Java,Spring,Maven,Spring Mvc,Spring Boot,我的一个项目中有一个编译错误 未能执行目标org.apache.maven.plugins:maven编译器plugin:3.1:compile 因为它找不到我已经使用的另一个项目中的所有类 <dependency> <groupId>com.laberint</groupId> <artifactId>laberint-core</artifactId> <
<dependency>
<groupId>com.laberint</groupId>
<artifactId>laberint-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
只需从另一个项目创建一个jar,并将其添加到当前项目的本地lib目录中。另一个选项是将jar文件安装到本地maven存储库中,如下所示:-
mvn install:yourlocal-jarfile
-Dfile=<path-to-your jar>
-DgroupId=<group-id> --> the group that the file should be registered under
-DartifactId=<artifact-id> --> give a artifact name to your jar
-Dversion=<version> --> version of your jar file
-Dpackaging=<packaging> --> jar
-DgeneratePom=true
mvn安装:您的本地文件
-D文件=
-DgroupId=-->文件应在其下注册的组
-DartifactId=-->为您的jar提供工件名称
-Dversion=-->jar文件的版本
-dpackage=-->jar
-DgeneratePom=true
您也可以尝试以下选项:-
<dependency>
<groupId>com.laberint</groupId>
<artifactId>laberint-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<systemPath>/pathto/yourJar.jar</systemPath>
</dependency>
com.laberint
标芯
0.0.1-快照
/路径/yourJar.jar
希望这能帮助你的工作。祝你好运 如您在评论中所述,您正在与您试图构建的项目相同的
Eclipse
工作区中开发laberint core
项目。您的问题是,Eclipse
知道您工作区中的每个项目,并且可以解决这些项目依赖关系,Maven
没有这些信息,这意味着它会搜索存储库(您在~/.m2
和Maven Central
中的本地存储库)以查找依赖关系
正如您所说,您已经通过mvn install
将laberint core
项目安装到本地Maven
存储库中。这就是为什么Maven
可以找到依赖项,而您没有得到依赖项无法解决的异常的原因,但我猜您是在一段时间前安装了依赖项,因此您在Eclipse
项目中创建的一些类在安装后丢失了
有两种方法可以解决此问题
每次在构建主项目之前创建并安装依赖项jar
这意味着在构建主项目时需要更多的手动开销,但如果您只在Eclipse
中构建,而不是直接从命令行构建,则可以实现自动化
创建一个聚合器项目,如图所示
这基本上是第三个项目,它只包含一个类似以下内容的pom.xml
文件:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.laberint</groupId>
<artifactId>aggregator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>relative/path/to/laberint-core</module>
<module>relative/path/to/laberint-main</module>
</modules>
</project>
4.0.0
com.laberint
聚合器
0.0.1-快照
聚甲醛
相对/路径/到/标签核心
相对/路径/到/标签主
要构建项目,您可以调用在聚合器项目之前在主项目上调用的目标。基本上,如果您以前从主项目的根目录调用了mvn package
,您现在将切换到聚合器项目的根目录并调用mvn package
。按照惯例,聚合器pom应位于其模块的父目录中。请发布mvn依赖项:树
输出。阅读错误消息。确定缺少的类。找到它不属于哪个图书馆。在Maven repo中打开该库的jar文件。检查类是否存在于jar文件中的正确位置。您没有发布任何有助于我们发现问题的内容:pom不完整,错误消息不完整,我们不知道缺少的类,您的Maven repo的内容,等等。laberint-core
是你的项目吗?你是否在与你试图构建的项目相同的Eclipse
工作区中开发它?是的,laberint-core是我在同一个Eclipse工作区中的项目
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.laberint</groupId>
<artifactId>aggregator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>relative/path/to/laberint-core</module>
<module>relative/path/to/laberint-main</module>
</modules>
</project>