0

I have a single java file to compile. It uses javax.servlet-api-3.1.0.jar. I added it to maven with mvn-install and it says it built successfully. However, in Intellij it still throws errors during compilation saying:

package javax.servlet does not exist.

This was after restarting it.

Am I missing anything with adding this jar to my program?

Thanks!

  • Could you please provide your `pom.xml` ? – Mickael Jun 30 '17 at 14:25
  • There isn't one. I just have a single .java file. –  Jun 30 '17 at 14:33
  • How do you resolve the dependencies of your project ? You need to say somewhere what JARs your project needs to compile. – Mickael Jun 30 '17 at 14:46
  • See https://www.jetbrains.com/help/idea/2017.1/working-with-module-dependencies.html. – CrazyCoder Jun 30 '17 at 14:55
  • Thanks CrazyCoder, the link you posted helped with managing module dependencies. I was able to add the jar. I also created a pom.xml in the project. Not sure which one did it, but I got it to compile. –  Jun 30 '17 at 15:18

1 Answers1

0

You need a pom.xml file in order to build a maven based project. In short, a pom.xml file is used to tell maven how exactly to build your project, and what dependencies it requires. I'd strongly recommend reading the quickstart guide for maven here

Thorntonz
  • 46
  • 2
  • Thanks, I created a pom.xml plus added the jar in File -> Project Structure -> Modules. It compiles now. –  Jun 30 '17 at 15:19
  • @dansmith841 -- you shouldn't add the jar manually to the module, maven does this for you. Close your project, then open a project, choosing your pom as the project file. Idea will do the rest, including importing your dependencies for you. – Software Engineer Jun 30 '17 at 21:53