You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NetBeans中Maven项目引入OkHttp3报错:com.squareup包不存在

Troubleshooting OkHttp 3 Import Issue in NetBeans Maven Project

Hey Diego, let's work through this issue step by step—since you're new to Java, Maven, and NetBeans, I'll keep things clear and actionable.

First, Let's Confirm the Core Issue: OkHttp 3's Package Structure Change

A common pitfall when upgrading from OkHttp 2.x to 3.x is the package name change:

  • OkHttp 2.x used com.squareup.okhttp.*
  • OkHttp 3.x simplifies this to just okhttp3.* (no com.squareup prefix!)

That's likely why you're seeing the "package com.squareup does not exist" error—you're trying to import a package that no longer exists in OkHttp 3.

Step-by-Step Fixes

1. Verify Your Maven Dependency is Correct

Double-check your pom.xml has the right OkHttp 3 dependency (you mentioned you fixed the groupId, but let's confirm):

<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
    <version>3.9.0</version>
</dependency>

2. Force Maven to Refresh Dependencies

NetBeans might be holding onto cached old dependencies. Do this:

  • Right-click your project in the Projects window
  • Hover over Maven → Select Clean and Build
  • Alternatively, open the terminal in your project root and run:
    mvn clean install -U
    
    The -U flag forces Maven to update all dependencies, bypassing cached versions.

3. Update Your Import Statements

Replace any old OkHttp 2 imports with OkHttp 3's correct paths. For example:

  • ❌ Wrong: import com.squareup.okhttp3.OkHttpClient;
  • ✅ Correct: import okhttp3.OkHttpClient;

Common OkHttp 3 classes you might need:

  • okhttp3.OkHttpClient
  • okhttp3.Request
  • okhttp3.Response
  • okhttp3.MediaType

4. Reload the Project in NetBeans

Sometimes IDEs don't sync dependency changes automatically:

  • Right-click your project → Select Reload Project
  • Check the Dependencies folder in the Projects window—you should see okhttp-3.9.0 listed (not the old 2.7.2 version)

5. Clear NetBeans Cache (If All Else Fails)

If the error persists, NetBeans' cache might be corrupted:

  1. Close NetBeans completely
  2. Find the cache directory:
    • On Windows: C:\Users\<YourUsername>\AppData\Roaming\NetBeans\<NetBeansVersion>\var\cache
    • On macOS/Linux: ~/.netbeans/<NetBeansVersion>/var/cache
  3. Delete the entire cache folder
  4. Reopen NetBeans and load your project again

内容的提问来源于stack exchange,提问作者Diego Alves

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:38:06