4

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?

Roy
  • 277
  • 1
  • 5
  • 17
  • 1
    Have you set up your Project properly? If you get errors about nonexisting packages it might indicate you don't have the proper library referenced. Take a look around the help section on IntelliJ on how to add libraries and modules and so on: https://www.jetbrains.com/idea/help/configuring-project-structure.html – trappski Aug 21 '15 at 05:20

2 Answers2

3

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

Community
  • 1
  • 1
Zarwan
  • 5,537
  • 4
  • 30
  • 48
  • Thanks, this helped me move on to the next issue. I have another problem now - please see edited question above. I can't access org.jdom.Document - though I have installed jdom in my project structure – Roy Aug 21 '15 at 05:48
  • @Roy you mean you added the jar for org.jdom as well? Go to where you downloaded it and go through it using 7zip or something. Check if there is a Document class in org/jdom – Zarwan Aug 21 '15 at 05:52
  • Yes, there is (jdom-2.0.6-javadoc.jar). What should I do? Should I add it separately - or as part of a whole directory (jdom-2.0.6)? – Roy Aug 21 '15 at 05:54
  • @Roy what do you mean? Did you add the jar as you did the one I linked in my question? – Zarwan Aug 21 '15 at 05:55
  • The jdom.zip unzips into a folder with multiple jar and lib folder. Should I add the jdom-2.0.6 folder or the multiple jar files separately? – Roy Aug 21 '15 at 05:57
  • @Roy I'm not sure. Zip files are typically treated the same as jars (ex. In Maven they both work) but I'm not 100% sure with IntelliJ. Adding the zip may or may not work. But I know adding the jars separately will work for sure. You can just do that, or try adding the zip and if it doesn't work add them individually then. – Zarwan Aug 21 '15 at 06:01
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/87551/discussion-between-roy-and-zar). – Roy Aug 21 '15 at 06:06
1

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.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Patrick Gotthard
  • 1,101
  • 1
  • 8
  • 10