Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using "provided" classpath in tomcat7-maven-plugin goals

I have some dependencies in my webapp that I've marked as provided because I expect them to be provided by an appserver (maybe a production environment provides these dependencies at the specified versions). How do I simulate that when I'm running tests or in development on my localhost using for example the tomcat7-maven-plugin goals like run?

I can't see any way to do it without manually copying jars around. I can see how to use the test classpath - is there something wrong with what I'm trying to do?

like image 520
brabster Avatar asked Nov 03 '22 19:11

brabster


1 Answers

OK, I've found a way of getting this to work - it's reasonable but there's a duplication of dependency information and a magic profile... I feel that the tomcat7-maven-plugin should provide a means of making provided dependencies available in the container when running.

Add a profile that is activated when the tomcat plugin runs, and add the dependencies that have provided scope with compile scope to that profile, eg.

... in project pom ...
<dependencies>
  <dependency>
    <groupId>com.mycompany</groupId>
    <artifactId>my-provided-artifact</artifactId>
    <version>1.2.3</version>
    <scope>provided</scope>
  </dependency>
</dependencies>
...
<profiles>
  <profile>
    <!-- profile activated as cli param when tomcat7 plugin runs -->
    <id>tomcat</id>
    <dependencies>
      <dependency>
        <groupId>com.mycompany</groupId>
        <artifactId>my-provided-artifact</artifactId>
        <version>1.2.3</version>
        <scope>compile</scope>
      </dependency>
    </dependencies>
  </profile>
</profiles>
like image 128
brabster Avatar answered Nov 10 '22 15:11

brabster