Home > OS >  Project in eclipse not resolving jars present in Maven dependency
Project in eclipse not resolving jars present in Maven dependency

Time:11-14

I become pretty much confused while working with eclipse and maven. I am trying to create a project which has the package structure as below:

enter image description here

Now in DbSIngleton.java file I am referencing EmbeddedDriver class org.apache.derby.jdbc package. But it is unable to resolve that, which is strange as the jar is present in the maven dependencies as shown in the image. Also there is another jar twitter4j which is getting referenced without any error. Why is it failing for this derby jar? AM I missing something?

The code:

private DbSingleton() {
    
    try {
        DriverManager.registerDriver(new org.apache.derby.jdbc.EmbeddedDriver());
    } catch (SQLException e) {
        e.printStackTrace();
    }
    
    if(conn != null) {
        throw new RuntimeException("Use getConnection() method to create");
    }
    
    if(instance != null) {
        throw new RuntimeException("Use getInstance() method to create");
    }
}  

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
 
   <groupId>com.example</groupId>
   <artifactId>demo</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>jar</packaging>
 
   <name>demo</name>
   <url>http://maven.apache.org</url>
 
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
 
   <dependencies>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.1</version>
       <scope>test</scope>
     </dependency>
      <dependency>
            <groupId>org.twitter4j</groupId>
            <artifactId>twitter4j-core</artifactId>
            <version>[4.0,)</version>
      </dependency>
 <!-- https://mvnrepository.com/artifact/org.apache.derby/derby -->
 <dependency>
     <groupId>org.apache.derby</groupId>
     <artifactId>derby</artifactId>
     <version>10.11.1.1</version>
     <scope>test</scope>
 </dependency>
 
 
   </dependencies>
 </project>

CodePudding user response:

Please remove the test scope

<dependency>
     <groupId>org.apache.derby</groupId>
     <artifactId>derby</artifactId>
     <version>10.11.1.1</version>
     <scope>test</scope>
 </dependency>

should be

<dependency>
     <groupId>org.apache.derby</groupId>
     <artifactId>derby</artifactId>
     <version>10.11.1.1</version>
 </dependency>

Twitter dependency is in the default scope. Hence it is getting resolved.

  • Related