Maven: exec-maven-plugin 设置 classpathScope

因为项目的pom文件中依赖定义scope为provided,只能在compile与test阶段引入,如下。

<dependency>
    <groupId>${project.groupId}</groupId>
    <artifactId>atser-common</artifactId>
    <version>${project.parent.version}</version>
    <scope>provided</scope>
</dependency>

通过maven exec-maven-plugin 执行调用java执行main函数如下

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <executions>
                    <execution>
                        <id>pythoncodegenerator</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>com.hhasdf.PythonCodeGenerator</mainClass>
                            <arguments>
                                <argument>D:\\testcode\\</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

程序会报java.lang.NoClassDefFoundError错误,这是因为在plugin的java阶段,classpath找不到依赖范围是provided级别的jar包。

这里解决方法为修改该task的classpath范围,修改为生命周期为compile阶段:<classpathScope>compile</classpathScope>

此时就不会找不到依赖啦~

有问题还可以查阅plugins的官方文档地址:https://www.mojohaus.org/exec-maven-plugin/index.html,讲的蛮详细的。

猜你喜欢

转载自www.cnblogs.com/xun-meng/p/12158077.html