exec-maven-plugin无法找到或加载主类,但输出在命令行上运行正常

vog*_*lla 5 java xml maven exec-maven-plugin

我尝试使用exec-maven-plugin来运行Java程序.

我使用以下pom片段:

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
             <configuration>
                    <executable>java</executable>
                        <arguments>
                         <argument>-Dmyproperty=myvalue</argument>
                            <argument>-cp</argument>
                            <argument>"/home/vogella/libs/*"</argument>
                            <argument>com.vogella.test.Main</argument>
                        </arguments>
    </configuration>


</plugin>
Run Code Online (Sandbox Code Playgroud)

该类com.vogella.test.Main包含在一个jar文件中,该文件位于/ home/vogella/libs/*中.如果我运行该mvn -X clean install exec:exec命令,我看到以下错误消息:

[DEBUG]执行命令行:java -Dmyproperty = myvalue -cp"/ home/vogella/libs/*"com.vogella.test.Main错误:无法找到或加载主类com.vogella.test.Main

如果我java -Dmyproperty=myvalue -cp "/home/vogella/libs/*" com.vogella.test.Main在我启动Maven构建的shell中复制命令行(),那么Java程序将正确执行.

知道我的Maven设置有什么问题吗?

Mic*_*ael 4

使用 CLI,/home/vogella/libs/* 表达式由 bash 扩展并解析为文件列表。使用Maven,表达式是直接执行的,而不是展开的。所以它仍然是“/home/vogella/libs/*”,这不是一个有效的 jar 文件。通过使用 antrun 插件并在脚本中使用 java Ant 任务,您可能会取得更大的成功。Ant 比其他任何东西都更了解通配符。