java – Maven exec插件ClassNotFoundException
|
我正在使用Maven exec插件从命令行运行 java应用程序,命令为mvn exec:java.我已经在pom.xml中指定了主类以及相关的依赖项. <groupId>com.example.MyApp</groupId>
<artifactId>MyApp</artifactId>
<version>1.0.0</version>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.example.myclass</mainClass>
<arguments>
<argument>configFile</argument>
<argument>properties</argument>
</arguments>
</configuration>
</plugin>
我还指定了一些依赖… <dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.example.MyLibrary</groupId>
<artifactId>MyLibrary</artifactId>
<version>1.0.0</version>
</dependency>
MyApp程序读取一个配置文件,该文件作为命令行参数传入.配置文件包含位于MyLibrary中的类的名称.所以该类可以是com.mypackage.driver.MyClass,它位于MyLibrary中,它是上面列出的MyApp jar的依赖项. —-更新 ClassLoader loader = ClassLoader.getSystemClassLoader(); 我认为这是导致问题,因为它正在寻找默认类路径上不包含依赖项的类. 我在这里做错了什么提示? 解决方法你还在寻找这个问题的答案吗?我有完全相同的问题,最后想出来了.您需要在配置中添加includePluginDependencies,以使插件搜索主类的依赖项: <configuration>
<includePluginDependencies>true</includePluginDependencies>
<mainClass>com.example.myclass</mainClass>
<arguments>
<argument>configFile</argument>
<argument>properties</argument>
</arguments>
</configuration>
见:http://mojo.codehaus.org/exec-maven-plugin/java-mojo.html#includePluginDependencies (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
