Java Maven throws "package does not exist"

64 Views Asked by At

I have an APIClient class autogenerated from an OpenAPI yml file. Compiling was successful but running the app throws exceptions "java: package com.google.gson.reflect does not exist" and "java: package okhttp3 does not exist". The pom file contains these two packages. The digitalform ords client used the same codes but worked fine. I compared these two pom files and there are no differences. why does it throw runtime errors?

Error message:

C:\jag\jag-rsbc-digital-forms-vips-integration-17\jag-vips-client\src\jag-vips-client\target\generated-sources\openapi\src\main\java\ca\bc\gov\open\jag\ordsvipsclient\api\DisclosureApi.java:25:31
java: package com.google.gson.reflect does not exist
C:\jag\jag-rsbc-digital-forms-vips-integration-17\jag-vips-client\src\jag-vips-client\target\generated-sources\openapi\src\main\java\ca\bc\gov\open\jag\ordsvipsclient\api\DisclosureApi.java:93:19
java: package okhttp3 does not exist

POM.xml

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.10.1</version>
</dependency>
<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
    <version>4.11.0</version>
</dependency>

enter image description here

2

There are 2 best solutions below

0
jianmin tu On

after clone/rebuild the application, I got everything working now. Intellij is just weird.

0
Emir Alkal On

In such cases you can use maven command line application. Its name is mvn. All you have to do is change CWD(current working directory) to your project directory

$ cd /../../your_project_dir

And you can run mvn here. It's simple. IntelliJ and Eclipse use cache mechanism everywhere. Because of caching problems such problems can occur.