无法在Intellij中解析符号Apache

时间:2018-06-21 10:35:51

标签: java apache maven

我已经经历了其他答案,但似乎没有一个对我有帮助。我只是从编程开始。

import jdk.incubator.http.HttpClient;
import jdk.incubator.http.HttpResponse;
import org.apache.*;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;


public class app {
    public static void main(String[] args) throws JSONException, IOException {
        HttpClient client = HttpClients.createDefault();
        HttpGet get = new HttpGet("https://www.youtube.com/watch?v=Qdjna4Nh7DM");
        HttpResponse res = client.execute(get);

        String strng = EntityUtils.toString(res.getEntity());
        System.out.println(strng);
        String str1 = "playability";
        if(strng.toLowerCase().contains(str1.toLowerCase())){
            System.out.println("waah");
        }
        else{
            System.out.println("naah");
        }
    }
}

我正在尝试从站点中获取数据,并查看其中是否包含世界可玩性。

我遇到的问题是intellij无法在此处解决符号apache。

我已经使用以下pom.xml构建了一个Maven项目

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>driverscrape</groupId>
    <artifactId>driverscrape</artifactId>
    <version>1.0-SNAPSHOT</version>


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

我想念什么吗?还有什么我应该做的吗?请指导我!

2 个答案:

答案 0 :(得分:1)

尝试将apache http软件包作为依赖项添加到pom.xml中

<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.3.6</version>
</dependency>   

注意:请检查确切的包裹名称

答案 1 :(得分:1)

尝试将其添加到pom.xml</build>之间的</project>

<dependencies>
    <dependency>
          <groupId>org.apache.httpcomponents</groupId>
          <artifactId>httpclient</artifactId>
          <version>4.5.5</version>
    </dependency>
</dependencies>

说明:您缺少库。您需要告诉您的项目所需的库,如何调用库以及所需的版本。