Gradle依赖json简单错误 [英] Gradle dependency json-simple error

查看:1048
本文介绍了Gradle依赖json简单错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Gradle还是很陌生,所以我试图构建Java项目,但不确定相关性.我从未将Gradle配置为能够进行测试,或者现在没有jar文件来进行编译和运行.

I'm fairly new to Gradle so I'm trying to build a Java project and not sure about the dependencies. I have never gotten Gradle configured to be able to do my tests or now a jar file to compile and run.

我的build.gradle:

apply plugin: 'java'
apply plugin: 'maven'

repositories {
   jcenter()
}

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.25'
    compile 'org.json:json:20160212'
    testCompile 'junit:junit:4.12'
}

这就是我在控制台上看到的内容,它看不到我的导入内容:

And this is what I get on the console stating that it doesn't see my import:

 error: package org.json.simple does not exist
 import org.json.simple.JSONParser;

这是我的课程:

import org.json.simple.*;
import java.io.*;
import java.util.*;
import java.lang.*;

public class FileLoader {
  @SuppressWarnings("unchecked")
  public static void main(String args[]) {
    JSONParser parser = new JSONParser();
    int count = 0;

    try {
      Object obj = parser.parse(new FileReader(
          "Consumers.json"));

      JSONObject jsonObject = (JSONObject) obj;
      JSONArray array = jsonObject.getJSONArray("people");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

推荐答案

如果下载 JSON jar ,并列出其内容(例如,使用jar tf),其中不包含org.json.simple包.

If you download the JSON jar specified, and list its contents (e.g. with jar tf), it does not contain the org.json.simple package.

所以问题很简单,就是您需要另一个jar.

So the problem is simply that you need another jar.

我不知道这是否是意图,但有根据的猜测:如果将此依赖项添加到build.gradle:

I don't know if this is the intent, but an educated guess: if you add this dependency to build.gradle:

compile 'com.googlecode.json-simple:json-simple:1.1.1'

和这些进口:

import org.json.simple.parser.*;
// import org.json.simple.*;
import org.json.*;

然后为我编译示例.

这篇关于Gradle依赖json简单错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆