Maven exec plugin- how to include “system” classpath?

后端 未结 4 701
情话喂你
情话喂你 2020-12-17 14:35

I have a project that uses \"system\" scope to specify a jar file included in my project\'s WEB-INF/lib dir. This artifact is not in any of the maven repositori

相关标签:
4条回答
  • 2020-12-17 15:12

    As E.G. pointed out, the solution is to use the compile scope when running exec.

    On each invocation:

    mvn exec:java -Dexec.classpathScope=compile
    

    or directly in the exec-plugin-configuration:

         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            ...
            <configuration>
                  <classpathScope>compile</classpathScope>
            </configuration>
        </plugin>
    
    0 讨论(0)
  • 2020-12-17 15:18

    Interesting to know that classpathScope=system drops runtime dependencies. I found that by including it as a plugin in the pom.xml works as an alternative. Could you please try and let me know if it works for you too?

    So I added a system level dependency to commons-collection as an example like you have for your artifact:-

     <dependency>
            <groupId>commons-collections</groupId>
          <artifactId>commons-collections</artifactId>
          <version>3.0</version>
            <scope>system</scope>
            <systemPath>C:\\<some_path>\\commons-collections-3.0.jar</systemPath>
        </dependency>
    

    Then in the <build> tag I have the exec-maven-plugin plugin to be executed in the install phase:-

    <plugin>
       <groupId>org.codehaus.mojo</groupId>
       <artifactId>exec-maven-plugin</artifactId>
       <version>1.1</version>
       <executions>
        <execution>
         <phase>install</phase>
         <goals>
          <goal>java</goal>
         </goals>
         <configuration>
          <mainClass>com.stackoverflow.test.App</mainClass>
         </configuration>
        </execution>
       </executions>
      </plugin>
    

    Then I ran mvn install. I also made sure com.stackoverflow.test.App class has some code that invokes a class from commons-collections-3.0.

    Hope this helps.

    0 讨论(0)
  • 2020-12-17 15:21

    The right answer is to use the maven-install-plugin and Put The Jar Into Your Local Repo. Or, better yet, run nexus or artifactory and use the deploy plugin to put the jar into there. System classpath is just a world of hurt.

    0 讨论(0)
  • 2020-12-17 15:37

    Use 'compile' scope to run maven exec plugin - mvn exec:java -Dexec.classpathScope=compile. This will include system-scoped dependencies.

    0 讨论(0)
提交回复
热议问题