3

I'm trying to make use of a jReddit library, which, in turn requires apache HttpComponents and Commons IO libraries.

I downloaded the sources, added them in Itellij Idea through File - Project Structure - Modules - Add Content Root.

All the classes from the libraries that my code makes use of are imported successfully. But the problem appears when compiling - it says that package com.github.jreddit.oauth does not exist and package org.apache.http.impl.client does not exist and that it cannot find symbol of those libraries' classes.

Why does this happen and how to fix it?

parsecer
  • 4,758
  • 13
  • 71
  • 140
  • 1
    Why aren't you using maven? – Oleg Aug 13 '17 at 21:14
  • @Oleg, I never used it before.. – parsecer Aug 13 '17 at 21:17
  • 1
    Possible duplicate of https://stackoverflow.com/questions/20137020/package-doesnt-exist-error-in-intellij. And I agree with @Oleg - cosider using `maven` or better `gradle` to build your projects – Ivan Pronin Aug 13 '17 at 21:28
  • 1
    @IvanPronin Which one is better is extremely debatable. From my personal experience it's much better to use `maven`. – Oleg Aug 14 '17 at 10:43
  • Well, gradle can do everything that maven can + adds far more features +it uses groovy (endless flexibility) + requires less efforts to do the same things with maven. Maven becomes outdated nowadays. – Ivan Pronin Aug 14 '17 at 14:40
  • @IvanPronin All those points can be disputed, this is really not the place for such a discussion. You can read https://www.reddit.com/r/java/comments/5eoxxp/gradle_vs_maven_current_thoughts/ and just assume that I said everything that people arguing for maven said. For what OP needs it really doesn't matter which build tool he will use, unfortunately he received some bad advice from a high rep user telling him not to use one. – Oleg Aug 15 '17 at 12:40
  • 1
    @Oleg, Hey, I'd take your advice into consideration, it's just I really need a quick solution for now, but I do intend to learn maven later on. – parsecer Aug 15 '17 at 19:51

2 Answers2

1

Don't use Maven or Gradle if you can't even manage adding a JAR to your project manually.

You should acquire those JARs (containing .class byte code files, not .java source), add them a folder in your project named /lib, and add that directory as a JAR source location in your project. They'll be in the CLASSPATH then.

You need to add the /lib folder to an artifact when you run. Be sure you know how to do that as well.

duffymo
  • 305,152
  • 44
  • 369
  • 561
1

I ran into this error after upgrading IntelliJ to version 2019.1. These steps fixed it for me:

  1. Click Run from the toolbar
  2. Choose Edit Configurations
  3. Make sure the Scratch file you want to run is selected on the left panel
  4. In Use classpath of module dropdown, select the project module that contains the proper module
vishal
  • 895
  • 1
  • 9
  • 25