Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 have 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.

like image 537
George Armhold Avatar asked Mar 12 '11 23:03

George Armhold


People also ask

Does Maven use classpath?

When Maven's Surefire plugin executes unit tests of a project, developers do not need to provide the classpath containing all dependencies. Instead, Maven sets up the required classpath. Other plugins utilize the Maven generated classpath, too.

What is the correct syntax for executing a Maven plugin?

Usage of a Maven Plugin xml you can use the shorthand notation to execute the plugin: mvn <prefix>:<goal> , commonly the “prefix” is the artifact ID minus the “-maven-plugin”.

What does Mvn exec Java?

mvn exec:java is a goal from the exec plugin for maven. It lets you specify a main class to execute (see pom. xml). This lets you avoid having to figure out the proper java command to run and classpath arguments and the like.


1 Answers

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

like image 106
E.G. Avatar answered Sep 22 '22 14:09

E.G.