user2066936
user2066936

Reputation:

Running Tomcat Maven plugin with added project provided dependency

Need to be pointed in the right direction on this perhaps, but if I add a "provided" dependency that is not included in the tomcat set of provided dependencies, running tomcat7:run from within eclipse fails with a classnotfoundexception on the class from the provided scope jar.

It needs to "provided" because it's a custom jar from a separate project that I've run mvn install on and for production am copying the jar to the $CATALINA_BASE/shared directory so that it's available (as a singleton) across applications/webapps.

    <dependency>
        <groupId>IndexFileAccessTracker</groupId>
        <artifactId>IndexFileAccessTracker</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <scope>provided</scope>
    </dependency>

Only way I see (with my limited knowledge of Maven and the Tomcat7 plugin) is to change the scope to compile when running tomcat from the plugin in Eclipse and then change the scope back to provided when running the package goal.

Are there solutions to this? I tried adding the dependency to the the tomcat maven plugin (keeping the main maven dependency as provided but got the same class not found error:

            <!-- For Maven Tomcat Plugin -->
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <path>/CounterWebApp</path>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>IndexFileAccessTracker</groupId>
                    <artifactId>IndexFileAccessTracker</artifactId>
                    <version>0.0.1-SNAPSHOT</version>
                    <scope>compile</scope>
                </dependency>
            </dependencies>
        </plugin>

Again, it needs to be provided in the main Maven dependency because I don't want it included in the deployed WAR.

Upvotes: 0

Views: 2128

Answers (2)

user2066936
user2066936

Reputation:

Resolved by using profiles, similar to https://stackoverflow.com/a/5951630

...
</dependencies>
<profiles>
<profile>
    <id>runineclipse</id>
    <dependencies>
        <dependency>
            <groupId>IndexFileAccessTracker</groupId>
            <artifactId>IndexFileAccessTracker</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
</profile>  
</profiles>
<build>
...

Then in my run/debug configuration just added runineclipse to the Profiles: box. (On a side note, to do step through debugging I had to manually add the project to the Source tab.)

The build configuration was just the same package in the Goals: box; and I left the original dependency to have scope provided.

Upvotes: 1

Hendrik Jander
Hendrik Jander

Reputation: 5715

The tomcat7-maven-plugin and its run goal

Requires dependency resolution of artifacts in scope: test

Everythig that is on the compile classpath is also on the test classpath. Thats why it is working with scope compile.

So the solution in your case would be to mark your dependency as test what even is (imo) semantically correct.

This will make the library available at local test-time, but not in the final artifact.

Upvotes: 0

Related Questions