kiwilisk
kiwilisk

Reputation: 83

Maven provided scope and eclipse runtime classpath

I've got a problem with my eclipse classpath with the m2e plugin. I have a project which depends on other projects in my workspace. I've added these dependencies as maven dependencies with scope provided. I expect the scope to do the following: Provide the dependencies for compilation but exclude them for the runtime classpath. Because at runtime, these classes should be loaded from jars inside a folder.

But the eclipse classpath includes every single dependency I've provided in the project pom. Eclipse seems to ignore the provided scope. Is there any way to exclude those from runtime classpath?

Regards

Upvotes: 5

Views: 7263

Answers (3)

fwc
fwc

Reputation: 101

If you want dependencies to be "provided for compilation but excluded from runtime classpath" you need to use the "provided" dependency scope (a Maven term) rather than the "compile" scope, which Maven uses by default.

Upvotes: 1

Yu Jiaao
Yu Jiaao

Reputation: 4714

i faced the same problem with maven-war-plugin version 2.2, use maven-war-plugin ver. 2.3 the problem is gone, at minimum with mvn package command.

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>

            <configuration>
                <webxml>WebContent/WEB-INF/web.xml</webxml>
                <packagingExcludes>jsp-api-6.0.36.jar,el-api-6.0.36.jar,servlet-api-6.0.36.jar</packagingExcludes>              

            </configuration>
        </plugin>

Upvotes: 0

artbristol
artbristol

Reputation: 32407

m2e is doing its job properly here. I think you misunderstand the meaning of 'runtime'. Your project does in fact depend on the other projects at both compile and runtime and when you build it with Maven, the POM will reflect that. You would only use scope 'provided' if you were planning to deploy the project to e.g. an application server that provides the dependencies itself.

Upvotes: 0

Related Questions