How to use Java EE IntelliJ IDEA community edition
To add to CrazyCoder's answer. Add a GLOBAL library (I never saw this).
File -> Project Structure... -> Global Libraries -> + -> Java -> [choose root dir of server]
Configure a global library for your application server jars and add this global library to the module dependencies.