Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带有jackson lib gradle的eclipse类路径问题_Java_Eclipse_Gradle - Fatal编程技术网

Java 带有jackson lib gradle的eclipse类路径问题

Java 带有jackson lib gradle的eclipse类路径问题,java,eclipse,gradle,Java,Eclipse,Gradle,我的项目在EclipseOxygen和mars中打开过一次,我看到了一个在EclipseOxygen中导入jackson lib的修复程序(eclipse建议)——我这样做了,它解决了这个问题——尽管我已经在我的项目的gradle dependencies列表中提到了相同的依赖项 之后,我在EclipseMars中打开了同一个项目,依赖项显示在buildpath(eclipse deps列表)中,在我的gradle deps列表中,但EclipseMars仍然在源代码上显示错误 我清理了项目,也

我的项目在EclipseOxygen和mars中打开过一次,我看到了一个在EclipseOxygen中导入jackson lib的修复程序(eclipse建议)——我这样做了,它解决了这个问题——尽管我已经在我的项目的gradle dependencies列表中提到了相同的依赖项

之后,我在EclipseMars中打开了同一个项目,依赖项显示在buildpath(eclipse deps列表)中,在我的gradle deps列表中,但EclipseMars仍然在源代码上显示错误

我清理了项目,也清理了。/gradlew eclipse-一切都成功了,但是eclipse mars无法解决依赖关系-我应该如何解决这个问题

我的身材,格雷德尔是

/*
 * This build file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java Library project to get you started.
 * For more details take a look at the Java Libraries chapter in the Gradle
 * user guide available at https://docs.gradle.org/3.5/userguide/java_library_plugin.html
 */

// Apply the java-library plugin to add support for Java Library
apply plugin: 'java-library'
apply plugin: 'eclipse'

// In this section you declare where to find the dependencies of your project
repositories {
    // Use jcenter for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
    mavenCentral()
}

dependencies {
    // This dependency is exported to consumers, that is to say found on their compile classpath.
    api 'org.apache.commons:commons-math3:3.6.1'

    // This dependency is used internally, and not exposed to consumers on their own compile classpath.
    implementation 'com.google.guava:guava:21.0'

    // Use JUnit test framework
    testImplementation 'junit:junit:4.12'

    // https://mvnrepository.com/artifact/org.jsoup/jsoup
    compile group: 'org.jsoup', name: 'jsoup', version: '1.11.2'

    // https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.3'


}

这是我的ref代码

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Iterator;
import java.util.Scanner;
import java.util.regex.Pattern;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

public class Main {

//  public ObjectMapper mapper = new ObjectMapper();

    public static void main(String[] args) {
//      for (String html : args) {
//          Main main = new Main();
//          try {
//              main.parseHtml(html);
//          } catch (JsonProcessingException e) {
//              e.printStackTrace();
//          }
//      }

        Main main = new Main();

        String html = main.getFile("appleInc.html");
        try {
            main.parseHtml(html);
        } catch (JsonProcessingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private String getFile(String fileName) {

        StringBuilder result = new StringBuilder("");

        //Get file from resources folder
        ClassLoader classLoader = getClass().getClassLoader();
        File file = new File(classLoader.getResource(fileName).getFile());

        try (Scanner scanner = new Scanner(file)) {

            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                result.append(line).append("\n");
            }

            scanner.close();

        } catch (IOException e) {
            e.printStackTrace();
        }

        return result.toString();

      }

    public void parseHtml(String html) throws JsonProcessingException {
        Document document = Jsoup.parse(html);
        // parse all the table required
//      ArrayNode tableInfo = retrieveTableInfo(document);

        // get the metadata from the html
        ObjectNode metadataObject = retrieveMetadataInfo(document);
//      tableInfo.add(metadataObject);
//      System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(tableInfo));
    }

    @SuppressWarnings("unused")
    private ObjectNode retrieveMetadataInfo(Document document) {
        String type = document.getElementsByTag("type").text();
        String companyName = findCompanyName(document);
        String employerIdentificationNo = findEmployerIdentificationNumber(document);
        return null;
    }

    private String findEmployerIdentificationNumber(Document document) {
        String employerNo = "";
        employerNo = document.getElementsContainingText("I.R.S. Employer").prev("div").text();
        if (employerNo.isEmpty()) {
            Iterator<Element> iterator = document.getElementsContainingText("Employer Identification").prev("tr")
                    .iterator();
            while (iterator.hasNext()) {
                Element element = (Element) iterator.next();
                if (element.is("tr")) {
                    employerNo = element.getElementsMatchingText(getPattern()).text();
                }
            }
        }
        return null;
    }

    private Pattern getPattern() {
        String re1 = "(\\d+)";
        String re2 = "(-)";
        String re3 = "(\\d+)";

        return Pattern.compile(re1 + re2 + re3, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
    }

    private String findCompanyName(Document document) {
        return document.getElementsContainingText("Exact name of Registrant").prev("div").text();
    }

    private ArrayNode retrieveTableInfo(Document document) {
        Elements tables = document.getElementsByTag("table");
        tables.forEach(table -> {
            if (Validator.isTableUsefull(table))
                return;
            String tableTitle = getTableTitle(document, table);

        });

        return null;
    }

    private String getTableTitle(Document document, Element table) {
        // TODO Auto-generated method stub
        return null;
    }
}
导入java.io.File;
导入java.io.IOException;
导入java.net.URL;
导入java.util.Iterator;
导入java.util.Scanner;
导入java.util.regex.Pattern;
导入org.jsoup.jsoup;
导入org.jsoup.nodes.Document;
导入org.jsoup.nodes.Element;
导入org.jsoup.select.Elements;
导入com.fasterxml.jackson.core.JsonProcessingException;
导入com.fasterxml.jackson.databind.ObjectMapper;
导入com.fasterxml.jackson.databind.node.ArrayNode;
导入com.fasterxml.jackson.databind.node.ObjectNode;
公共班机{
//public ObjectMapper mapper=new ObjectMapper();
公共静态void main(字符串[]args){
//for(字符串html:args){
//Main Main=新Main();
//试一试{
//main.parseHtml(html);
//}catch(JsonProcessingException e){
//e.printStackTrace();
//          }
//      }
Main Main=新Main();
字符串html=main.getFile(“appleInc.html”);
试一试{
main.parseHtml(html);
}捕获(JsonProcessingException e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}
私有字符串getFile(字符串文件名){
StringBuilder结果=新的StringBuilder(“”);
//从资源文件夹获取文件
ClassLoader ClassLoader=getClass().getClassLoader();
File File=新文件(classLoader.getResource(fileName.getFile());
尝试(扫描仪=新扫描仪(文件)){
while(scanner.hasNextLine()){
字符串行=scanner.nextLine();
结果.append(行).append(“\n”);
}
scanner.close();
}捕获(IOE异常){
e、 printStackTrace();
}
返回result.toString();
}
public void parseHtml(字符串html)引发JsonProcessingException{
documentdocument=Jsoup.parse(html);
//解析所需的所有表
//ArrayNode tableInfo=retrieveTableInfo(文档);
//从html中获取元数据
ObjectNode metadataObject=retrieveMetadataInfo(文档);
//tableInfo.add(metadataObject);
//System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(tableInfo));
}
@抑制警告(“未使用”)
私有ObjectNode retrieveMetadataInfo(文档){
字符串类型=document.getElementsByTag(“类型”).text();
字符串companyName=findCompanyName(文档);
字符串employerIdentificationNo=findEmployerIdentificationNumber(文档);
返回null;
}
私有字符串findEmployerIdentificationNumber(文档){
字符串employerNo=“”;
employerNo=document.getElementsContainingText(“I.R.S.雇主”).prev(“div”).text();
if(employerNo.isEmpty()){
迭代器迭代器=document.getElementsContainingText(“雇主标识”).prev(“tr”)
.iterator();
while(iterator.hasNext()){
Element=(Element)迭代器.next();
if(元素is(“tr”)){
employerNo=element.getElementsMatchingText(getPattern()).text();
}
}
}
返回null;
}
私有模式getPattern(){
字符串re1=“(\\d+”;
字符串re2=“(”);
字符串re3=“(\\d+”;
返回Pattern.compile(re1+re2+re3,Pattern.CASE|u不区分| Pattern.DOTALL);
}
私有字符串findCompanyName(文档){
返回文档.getElementsContainingText(“注册人的确切名称”).prev(“div”).text();
}
专用ArrayNode retrieveTableInfo(文档){
元素表=document.getElementsByTag(“表”);
tables.forEach(表->{
if(验证程序isTableUsefull(表))
返回;
String tableTitle=getTableTitle(文档,表格);
});
返回null;
}
私有字符串getTableTitle(文档、元素表){
//TODO自动生成的方法存根
返回null;
}
}

您使用的类不是jackson core的一部分。您可以通过浏览或查看jar文件的内容看到这一点

如您所见,包
com.fasterxml.jackson.core
中的类
JsonProcessingException
,找到时没有问题。那是因为它是杰克逊核心的一部分


缺少的类都在包
com.fasterxml.jackson.databind
中。要解决这些问题,您需要添加所需的库:
com.fasterxml.jackson.core:jackson-databind

您使用的类不是jackson-core的一部分。您可以通过浏览或查看jar文件的内容看到这一点

如您所见,包
com.fasterxml.jackson.core
中的类
JsonProcessingException
,找到时没有问题。那是因为它是杰克逊核心的一部分

缺少的类都在包
com.fasterxml.jackson.databind
中。要解决这些问题,您需要添加所需的库: