Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven 为什么依赖jar中存在编译错误,但仍然可以成功运行项目?_Maven - Fatal编程技术网

Maven 为什么依赖jar中存在编译错误,但仍然可以成功运行项目?

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

在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(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
            }
        }