Maven:无法解析类型。它是从所需的 .class 文件中间接引用的
Maven: The type cannot be resolved. It is indirectly referenced from required .class files
我将一些现有项目从 ant 项目更改为 maven 项目。
到目前为止一切顺利。
所有项目都具有相同的 groupId。
有一个名为 "ServerBase" 和 artifactId "server-base" 的项目。
在这个项目中有一个抽象 class "BaseService" 它通过以下方式定义了一个记录器:
import org.jboss.logging.Logger;
[...]
protected Logger log = Logger.getLogger(this.getClass());
还有另一个项目,名称为 "Server",artifactId 为 "server"。
在这个项目中,有一个 class ConfigurationDAOImpl 扩展了上面的 BaseService-Class。
在 ConfigurationDAOImpl 中,记录器日志用于创建一些输出。
在 "Server" 的 POM 文件中,我已声明:
<dependency>
<groupId>com.tcom.amadeus</groupId>
<artifactId>server-base</artifactId>
<version>${project.version}</version>
</dependency>
在 BuildPath 下,依赖项在 MavenDependencies 下显示得非常好。我之前从构建路径中删除了旧的 dirct/natural/ant-dependency 。
如果我删除它,我会收到很多关于丢失 classes 等的错误。
但是,尽管我确实有这种依赖性,但我在 eclipse 中遇到了以下错误(在制表符下):
The type org.apache.commons.logging.Log cannot be resolved. It is indirectly referenced from required .class files
Resource: ConfigurationDAPImpl.java
Path: /Server/src/main/...
Location: Line 24
Type: Java Problem
我尝试删除依赖项并再次添加它,但没有成功。
这两个项目都参考了 JAVA 1.8。
这两个项目的构建目标都是多次清理一个包。
两个项目都已通过右键单击或按 F5 进行了更新。
我正在使用 Eclipse 版本:Neon.1a Release (4.6.1)
我正在使用 apache-maven-3.3.9
我正在使用 m2e 插件。
任何进一步的帮助将不胜感激。
提前致谢。
看起来 apache 日志库不是从您的 server-base
项目中传递过来的。检查您是否在 MavenDependencies 下的项目 server
中看到 commons-logging
(apache logging) jar。如果没有,则将其添加为 server-base
项目中的 Maven 依赖项。
对 server-base
依赖的所有 jar 重复上述操作。
有两种方法可以'solve'这个:
1)
在 server-projects pom-file:
中显式添加所需的依赖项
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
2)
将 server-base-projects pom 文件中所需依赖项的范围从目前的 'provide' 更改为 'compile' 或完全删除范围标记,以便 maven 使用默认范围(我猜测是 'compile')
旧:
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<scope>provided</scope>
</dependency>
新:
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<scope></scope>
</dependency>
或:
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
文档中的一些背景信息:
provided This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example,
when building a web application for the Java Enterprise Edition, you
would set the dependency on the Servlet API and related Java EE APIs
to scope provided because the web container provides those classes.
This scope is only available on the compilation and test classpath,
and is not transitive.
谢谢大家。
我将一些现有项目从 ant 项目更改为 maven 项目。 到目前为止一切顺利。
所有项目都具有相同的 groupId。 有一个名为 "ServerBase" 和 artifactId "server-base" 的项目。 在这个项目中有一个抽象 class "BaseService" 它通过以下方式定义了一个记录器:
import org.jboss.logging.Logger;
[...]
protected Logger log = Logger.getLogger(this.getClass());
还有另一个项目,名称为 "Server",artifactId 为 "server"。 在这个项目中,有一个 class ConfigurationDAOImpl 扩展了上面的 BaseService-Class。 在 ConfigurationDAOImpl 中,记录器日志用于创建一些输出。
在 "Server" 的 POM 文件中,我已声明:
<dependency>
<groupId>com.tcom.amadeus</groupId>
<artifactId>server-base</artifactId>
<version>${project.version}</version>
</dependency>
在 BuildPath 下,依赖项在 MavenDependencies 下显示得非常好。我之前从构建路径中删除了旧的 dirct/natural/ant-dependency 。 如果我删除它,我会收到很多关于丢失 classes 等的错误。 但是,尽管我确实有这种依赖性,但我在 eclipse 中遇到了以下错误(在制表符下):
The type org.apache.commons.logging.Log cannot be resolved. It is indirectly referenced from required .class files
Resource: ConfigurationDAPImpl.java
Path: /Server/src/main/...
Location: Line 24
Type: Java Problem
我尝试删除依赖项并再次添加它,但没有成功。 这两个项目都参考了 JAVA 1.8。 这两个项目的构建目标都是多次清理一个包。 两个项目都已通过右键单击或按 F5 进行了更新。 我正在使用 Eclipse 版本:Neon.1a Release (4.6.1) 我正在使用 apache-maven-3.3.9 我正在使用 m2e 插件。
任何进一步的帮助将不胜感激。 提前致谢。
看起来 apache 日志库不是从您的 server-base
项目中传递过来的。检查您是否在 MavenDependencies 下的项目 server
中看到 commons-logging
(apache logging) jar。如果没有,则将其添加为 server-base
项目中的 Maven 依赖项。
对 server-base
依赖的所有 jar 重复上述操作。
有两种方法可以'solve'这个:
1) 在 server-projects pom-file:
中显式添加所需的依赖项<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
2) 将 server-base-projects pom 文件中所需依赖项的范围从目前的 'provide' 更改为 'compile' 或完全删除范围标记,以便 maven 使用默认范围(我猜测是 'compile')
旧:
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<scope>provided</scope>
</dependency>
新:
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<scope></scope>
</dependency>
或:
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
文档中的一些背景信息:
provided This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
谢谢大家。