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

已添加Jar包仍出现JSONArray类未找到异常(NoClassDefFoundError)求助

Fixing java.lang.NoClassDefFoundError: org/json/JSONArray in Servlet Projects

Hey there, let's work through this java.lang.NoClassDefFoundError: org/json/JSONArray problem you're hitting. You mentioned you've added the relevant JAR, but the runtime still can't find the class—this usually boils down to the JAR not being properly available to your application when it runs, not just during compilation. Here are actionable steps to fix it:

  • Ensure the JAR is in the correct runtime directory
    For web/servlet projects, adding the JAR to your IDE's build path is only half the battle. You need to place it directly in your project's WEB-INF/lib folder. If you're using an IDE like Eclipse or IntelliJ, confirm the JAR is included in your deployment assembly (Eclipse: Right-click project > Properties > Deployment Assembly; IntelliJ: File > Project Structure > Artifacts) to make sure it gets packaged into your WAR file.

  • Use build tools to manage dependencies (if applicable)
    If you're using Maven or Gradle, let the tool handle dependency management to avoid manual errors:

    • For Maven, add this to your pom.xml:
      <dependency>
          <groupId>org.json</groupId>
          <artifactId>json</artifactId>
          <version>20240303</version> <!-- Use the latest stable version -->
      </dependency>
      
    • For Gradle, add this to your build.gradle:
      implementation 'org.json:json:20240303'
      

    Run a build (mvn clean install or gradle build) to ensure the JAR is properly downloaded and included in your deployment.

  • Check for conflicting JARs
    Conflicts often happen if multiple versions of the JSON library (or other libraries that include org.json classes) exist in your classpath. Search your project's WEB-INF/lib and your application server's global lib directory for any duplicate or outdated JARs containing org/json/JSONArray, then remove the redundant ones.

  • Clean and rebuild your project
    IDEs sometimes cache old build artifacts that cause issues. Perform a full clean:

    • Eclipse: Go to Project > Clean and select your project
    • IntelliJ: Go to Build > Clean Project
      Then rebuild your project and redeploy it to your server.
  • Verify the JAR itself is valid
    It's possible the JAR you added is corrupted or doesn't actually contain the JSONArray class. Download a fresh copy of the official org.json JAR, open it with a zip tool, and confirm the org/json/JSONArray.class file exists inside.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 10:06:20