1

I have created a Maven project on Eclipse and have added the following dependency on the pom.xml file:

<dependency>
        <groupId>com.fasterxml</groupId>
        <artifactId>jackson-xml-databind</artifactId>
        <version>0.6.2</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.13.0</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.13.0</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.13.0</version>
</dependency>  

Then I use the following code to check if the dependency can be compiled:

import com.fasterxml.jackson.databind.ObjectMapper;

public class App 
{
    
    public static void main(String[] args) {
        ObjectMapper mapper = new ObjectMapper();
        
    }

}

Although Eclipse does not show any error, when I compile it using the following commands:

$ javac -sourcepath src  src\main\java\App.java

I recieve the following 3 errors:

src\main\java\App.java:6: error: package com.fasterxml.jackson.databind does not exist
import com.fasterxml.jackson.databind.ObjectMapper;
                                     ^
src\main\java\App.java:16: error: cannot find symbol
                ObjectMapper mapper = new ObjectMapper();
                ^
  symbol:   class ObjectMapper
  location: class App
src\main\java\App.java:16: error: cannot find symbol
                ObjectMapper mapper = new ObjectMapper();
                                          ^
  symbol:   class ObjectMapper
  location: class App
3 errors

Keep in mind that the corresponding JAR files to the dependancies are installed into the maven repository on the computer

1
  • 2
    You are not compiling with maven, but with javac. So It expects those jar files to be on classpath not in mvn Commented Oct 20, 2021 at 14:49

1 Answer 1

1

looks like your project is maven based, use maven command to compile it: cd to directory that contains pom.xml and run: mvn compile

Sign up to request clarification or add additional context in comments.

2 Comments

I did it, and now how can I run the main class using the command window?
to run it: mvn exec:java -Dexec.mainClass="com.mycompany.app.App"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.