2017-10-26 11 views
0

저는 자바 프로젝트를 만들려고 노력하고 있으므로 의존성에 대해 확신하지 못하기 때문에 Gradle에 대해 상당히 익숙합니다. 나는 테스트를 할 수 있도록 Gradle을 설정하거나 컴파일 및 실행을 위해 jar 파일을 만들지 못했습니다.Gradle dependency json-simple error

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' 
} 

그리고 이것이 내가 내 수입 보지 않는다는 콘솔에 무엇을 얻을 :

build.gradle

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(); 
    } 
    } 
} 
+0

어떤 버전의 Gradle이며 수업은 어떻게 생겼습니까? 문제를 재현하기 위해 최소한의 코드를 추가 할 수 있습니까? – mkobit

답변

0
: 여기

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

내 클래스의

JSON jar을 다운로드하고 해당 내용을 나열하면 (예 : jar tf), org.json.simple 패키지가 포함되어 있지 않습니다.

그래서 문제는 단순히 다른 항아리가 필요하다는 것입니다.

편집 :

이 의도이지만, 추측 경우 나도 몰라 :

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

이러한 수입 :

import org.json.simple.parser.*; 
// import org.json.simple.*; 
import org.json.*; 
당신이 build.gradle이 종속성을 추가하는 경우

그러면 예제가 컴파일됩니다 (나를 위해).

0

org.json.simple 라이브러리를 사용하는 올바른 종속성이 없습니다.

https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple과 같은 종속성에 대한 좌표를 원할 수도 있지만 Maven 좌표는 찾기 쉽지 않습니다.

당신이 당신의 빌드 스크립트에이 부분을 추가 할 수있는 라이브러리를 사용하고자하는 경우 :

repositories { 
    jcenter() 
} 

dependencies { 
    compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1' 
} 

가 수입 수정 파일이 추가 : 다음

import org.json.simple.parser.*; 

을, 당신은 단지에있는 클래스 정의에서 사용 오류를 수정하십시오.

또한이 라이브러리는 유지 보수되지 않은 것처럼 보이므로 다른 JSON 구문 분석 라이브러리를 탐색 할 수 있습니다.