我的项目在日食氧气和火星中打开了一次,我看到了修复导入日食氧气中的jackson lib(日食建议) - 我这样做了,它修复了那里的问题 - 虽然我已经提到了同样的依赖在我的项目的gradle依赖项列表中。
之后我在eclipse火星中打开了相同的项目,依赖项显示在buildpath(eps的deps列表)中,在我的gradle deps列表中,但是eclipse mars仍然在源代码上显示错误。
我清理了项目并完成了./gradlew eclipse - 一切都成功但是eclipse mars无法解决依赖 - 我应该如何解决这个问题。
我的build.gradle是
/*
* 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'
}
这是我的参考代码
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;
}
}
答案 0 :(得分:2)
您正在使用不属于jackson核心的类。正如您可以通过浏览the documentation或仅通过查看jar文件的内容来看到的。
如您所见,发现包JsonProcessingException
中的类com.fasterxml.jackson.core
没有问题。这是因为 是杰克逊核心的一部分。
缺少的类都在包com.fasterxml.jackson.databind
中。要解决这些问题,您需要添加所需的库:com.fasterxml.jackson.core:jackson-databind
。