Reputation: 3893
I need to use some jar dependency in runtime scope, but after changing it in pom.xml this dependency disappeared from dependency list. Classes from this dependency is used during compiling and running, so i need this dependency to be at runtime scope.
Upvotes: 0
Views: 85
Reputation: 48075
You might want to read about Maven Dependency scopes. The default scope is compile
and you should not change that unless you absolutely must.
compile - this is the default scope, used if none is specified. Compile dependencies are available in all classpaths.
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.
The easiest way to run some class in your project is to use the exec-maven-plugin
.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.example.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
Now you can run the project like this:
mvn package exec:java
That is easy and you don't have to think about the classpath setup.
Upvotes: 2
Reputation: 18228
If you need classes from your dependency while compiling then you should use compile
scope, which is the default.
In order to run your application you need all of the dependent jars to be on the classpath. You can use Maven in various ways to achieve that, but the correct scope is still compile
.
Upvotes: 2
Reputation: 199
If You use the classes from dependency in compilation, You need "compile" scope. Runtime dependency is not in compile classpath.
Upvotes: 3