简体   繁体   English

使用Jsoup库的问题

[英]Problems with use Jsoup library

I'm trying make a project using Jsoup library. 我正在尝试使用Jsoup库制作一个项目。 I imported the library using maven. 我使用maven导入了库。 My problem is when I have start to code using Jsoup classes and methods, eclipse don't show me anything available to import and to use from "org.jsoup" 我的问题是,当我开始使用Jsoup类和方法进行编码时,eclipse不会向我显示可从“ org.jsoup”导入和使用的任何内容。

I've already used Maven update project but my project has all dependencies placed right. 我已经使用过Maven更新项目,但是我的项目已将所有依赖项正确放置。

Someone got this problem too and could help me? 有人也遇到了这个问题,可以帮助我吗?

That is my current pom.xml on dependencies section: 那是我当前在依赖项部分的pom.xml:

<build>
    <finalName>crawler-api</finalName>
  </build>
  <properties>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
    <dependencies>
        <dependency>
          <groupId>javax.enterprise</groupId>
          <artifactId>cdi-api</artifactId>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>javax.annotation</groupId>
          <artifactId>jsr250-api</artifactId>
          <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.11.2</version>
            <scope>provided</scope>
        </dependency>
      </dependencies>

and my project libraries screenshot: project libraries 和我的项目库屏幕快照: 项目库

Well. 好。 After some struggles I will leave some details about what I did to solve my problem. 经过一番挣扎之后,我将保留一些有关解决问题的详细信息。

Unfortunately for some reason if you try add Jsoup library from maven repository I can get the classes and methods from the api. 不幸的是,由于某些原因,如果您尝试从Maven存储库添加Jsoup库,我可以从api获取类和方法。 I found some comments on github from people who said that the only solution for that is including the jars into your project. 我发现有人在github上发表了一些评论,他们说唯一的解决方案是将jars包含到您的项目中。 What sounds a bit old fashion. 听起来有点过时了。

Well. 好。 Let's get started. 让我们开始吧。

First, create a folder called lib into src/main/webapp/WEB-INF/ and have included the jsoup .jar that I have downloaded from the official web site. 首先,在src / main / webapp / WEB-INF /中创建一个名为lib的文件夹,其中包含我从官方网站下载的jsoup .jar。 After that I've added into pom.xml on dependencies section the follow child tag. 之后,我在“ dependencies”部分的pom.xml中添加了跟随子标记。

<dependency>
        <groupId>org.jsoup</groupId>
        <artifactId>jsoup</artifactId>
        <version>1.11.2</version>
        <scope>system</scope>
        <systemPath>${pom.basedir}/src/main/webapp/WEB-INF/lib/jsoup-1.11.2.jar</systemPath>
    </dependency>

So when I've started code my app using the classes and methods from the api everything seems available when I called. 因此,当我开始使用api中的类和方法对我的应用进行编码时,在调用时一切似乎都可用。 And after that when I built my artifact using maven the dependencies has been available inside my artifact. 之后,当我使用maven构建工件时,依赖关系就可以在工件内部使用了。

I really hope this could help someone. 我真的希望这可以帮助某人。 And I hope that the developers of Jsoup somehow fix that. 我希望Jsoup的开发人员以某种方式解决该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM