0

I'm working on a project with javaparser, I added the following maven dependencies -

<dependency>
    <groupId>com.github.javaparser</groupId>
    <artifactId>javaparser-core</artifactId>
    <version>3.24.0</version>
</dependency>

<dependency>
    <groupId>com.github.javaparser</groupId>
    <artifactId>javaparser-symbol-solver-core</artifactId>
    <version>3.24.0</version>
</dependency>

And when I am trying to use the package in my class, I am getting package not found error -

import com.github.javaparser.*;
^
ClassParser.java:7: error: package com.github.javaparser.ast does not exist
import com.github.javaparser.ast.*;
^
ClassParser.java:19: error: cannot find symbol
                        CompilationUnit compilationUnit = StaticJavaParser.parse(file);
                        ^
  symbol:   class CompilationUnit
  location: class ClassParser
ClassParser.java:19: error: cannot find symbol
                        CompilationUnit compilationUnit = StaticJavaParser.parse(file);
                                                          ^
  symbol:   variable StaticJavaParser
  location: class ClassParser
4 errors

What I have tried so far -

  • mvn clean install

  • mvn dependency:resolve

  • checked the package path to ensure I was importing from the correct path

  • Added both core and symbol solver dependencies

I have been stuck at it for hours now, any help would be really appreciated

fireWall
  • 1
  • 2
  • What IDE are you using? It may be a problem related with your IDE caches. Try cleaning the project or resetting the caches of your IDE – Jorge Campos Mar 07 '22 at 17:23
  • I'm using eclipse version 2021-12, not sure how to clear the cache though – fireWall Mar 07 '22 at 17:37
  • Update - I cleaned the cache but the error still exists – fireWall Mar 07 '22 at 17:56
  • Did you put the dependencies inside `` ? – J Fabian Meier Mar 07 '22 at 19:06
  • As far as I know, dependencyManagement is useful for managing all the dependencies but they don't actually import those dependencies. – fireWall Mar 07 '22 at 19:41
  • If you are on Eclipse please try Project -> Clean, then select you project and click on Clean. After that is finished right click on your project, Maven -> Update Project, select your project and click Ok. If you are running maven through the terminal it is also possible that the maven caches eclipse is using is not the same your terminal, so configuring maven in eclipse to be the same one as the terminal will also help to solve this problem. It will depend on your OS but it is roughly the same: https://stackoverflow.com/a/25468277/460557 – Jorge Campos Mar 07 '22 at 21:27

0 Answers0