Maven 为什么依赖jar中存在编译错误,但仍然可以成功运行项目?
在intellij idea中查看Maven 为什么依赖jar中存在编译错误,但仍然可以成功运行项目?,maven,Maven,在intellij idea中查看org.apache.commons.dbcp.BasicDataSource的源代码时,我发现了这个错误 Class 'BasicDataSource' must either be declared abstract or implement abstract method 'getParentLogger()' in 'CommonDataSource' public class Foo { public static void main(Str
org.apache.commons.dbcp.BasicDataSource的源代码时,我发现了这个错误
Class 'BasicDataSource' must either be declared abstract or implement abstract method 'getParentLogger()' in 'CommonDataSource'
public class Foo {
public static void main(String[] args) {
System.out.println("hello world");
}
interface IA{
String getParentLog();
}
class AImpl implements IA{
public void doSomething(){
System.out.println("doSomething");
}
}
}
我使用下面的maven依赖项
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
但是这次我不能运行它,并且有一个编译错误
Error:(14, 5) java: com.foobar.Foo.AImpl is not abstract and does not override abstract method getParentLog() in com.foobar.Foo.IA
为什么会这样?有两件事-
- 首先,与数据源相关的部分在用法上相互矛盾。我怀疑您可能在下载源代码后编辑了类
BasicDataSource
,或者使用了其他依赖项,从而引入了上述示例中实现的DataSource
类的另一个实现。请确认您没有使用在类路径中带来冲突类的任何其他依赖项
- 注意:在使用上述依赖项
commons dbcp:1.4
时,类DataSource
是从包javax.sql
中导入的,语法如下:
public interface DataSource extends javax.sql.CommonDataSource,
java.sql.Wrapper { .. }
- 第二部分,名为
AImpl
的类不是abstract
,在这种情况下,它必须定义它正在实现的接口的方法,如-
class AImpl implements IA{
public void doSomething(){
System.out.println("doSomething");
}
@Override
String getParentLog() {
/** Define how getParentLog is implemented in this class */
return null; // return string here after the above definition
}
}
有两件事-
- 首先,与数据源相关的部分在用法上相互矛盾。我怀疑您可能在下载源代码后编辑了类
BasicDataSource
,或者使用了其他依赖项,从而引入了上述示例中实现的DataSource
类的另一个实现。请确认您没有使用在类路径中带来冲突类的任何其他依赖项
- 注意:在使用上述依赖项
commons dbcp:1.4
时,类DataSource
是从包javax.sql
中导入的,语法如下:
public interface DataSource extends javax.sql.CommonDataSource,
java.sql.Wrapper { .. }
- 第二部分,名为
AImpl
的类不是abstract
,在这种情况下,它必须定义它正在实现的接口的方法,如-
class AImpl implements IA{
public void doSomething(){
System.out.println("doSomething");
}
@Override
String getParentLog() {
/** Define how getParentLog is implemented in this class */
return null; // return string here after the above definition
}
}