The short answer for your question is: you should use provided
scope.
Why not runtime
? Let's check Maven docs:
provided
This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
runtime
This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.
So, Maven may not expose runtime
scoped dependencies in compile's classpath, thus you won't be able to use them in you code directly. However, the code like Class.forName("class.from.runtime.Scope")
will compile ok.
I guess the problem is your IDE which didn't seized pom.xml
changes. Usually, this problem is fixed by "cleaning cache" or "updating" / "syncing" your project. Here is how to do this in Eclipse and IDEA.