开发者

Maven exec plugin- how to include "system" classpath?

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 repositories, so I must include it as part of my project. I do so with the following:

    <dependency>
        <groupId>com.example</groupId>
        <artifactId>MySpecialLib</artifactId>
        <version>1.2</version>
        <scope>system</scope>
        <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/MySpecialLib-1.2.jar</systemPath>
    </dependency>

This has worked great for most things.

But now I'm trying to run some code on the command line (outside of my webapp, via a main() method I ha开发者_运维问答ve added) and mvn exec:java can't resolve code in MySpecialLib because it's not included in the "runtime" classpath.

How can I either:

  • add MySpecialLib to the runtime classpath

or

  • tell mvn exec:java to also use the system classpath ?

I've tried mvn exec:java -Dexec.classpathScope=system, but that leaves off everything that's on runtime.


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


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>


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜