简体   繁体   中英

How to use ROME in Intellij?

How can I set up my project in Intellij to use the ROME library to read a RSS Feed ?

So far, I've developed the following:

import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.XmlReader;

import java.net.URL;

public class ReadRSS {

    public static void main(String[] args) {
        String urlString = "http://news.ycombinator.com/"
        boolean ok = false;
        if (args.length==1) {
            try {
                URL feedUrl = new URL(urlString);

                SyndFeedInput input = new SyndFeedInput();
                SyndFeed feed = input.build(new XmlReader(feedUrl));

                System.out.println(feed);

                ok = true;
            }
            catch (Exception ex) {
                ex.printStackTrace();
                System.out.println("ERROR: "+ex.getMessage());
            }
        }

        if (!ok) {
            System.out.println();
            System.out.println("FeedReader reads and prints any RSS/Atom feed type.");
            System.out.println("The first parameter must be the URL of the feed to read.");
            System.out.println();
        }
    }
}

But, I get multiple errors when running my code, mainly of the variant:

.. java:package com.sun.syndication.feed.synd does not exist..

How do I import the package in Intellij ? Managed to import this my adding jar in my project structure.

But the next problem is: I can't access org.jdom.Document - though I have installed jdom in my project structure. The error I get is

Error:(16, 38) java: cannot access org.jdom.Document class file for org.jdom.Document not found

How can I resolve this?

If you're using Maven or gradle add the dependency in your configuration file (ex. pom.xml in Maven) and do a build/install to download your dependencies. It should work fine after that. Dependency info is here: http://mvnrepository.com/artifact/rome/rome/0.9

Otherwise add the jar (downloadable from the link above) manually to your project. Look at the first answer in this question to see how to do this: Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project

I'm a developer of the ROME team. The latest version is ROME 1.5. It can be obtained from the central maven repository: http://search.maven.org/#artifactdetails%7Ccom.rometools%7Crome%7C1.5.1%7Cjar

The groupId has changed to com.rometools in v1.5.0.#

I highly recommend you to use Maven, Gradle or another build tool that is able to resolve transitive dependencies so you won't have to collect all dependencies manually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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