Maven package错误:You have to use a classifier to attach supplemental artifacts to the project instead
2017-11-17 10:22
4259 查看
我在pom.xml文件中添加了一个maven-jar-plugin的插件,目的是想多打一个jar包,如下:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.0.2</version> <executions> <execution> <id>service-jar</id> <phase>package</phase> <goals> <goal>jar</goal> </goals> <configuration> <classesDirectory>${project.build.directory}/webservice/</classesDirectory> </configuration> </execution> </executions> </plugin>目的是将webservice目录打包成jar包,运行mvn package之后,却报错了:
... [INFO] --- maven-jar-plugin:3.0.2:jar (make-a-jar) @ deploy --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 6.035 s [INFO] Finished at: 2017-11-17T09:25:22+08:00 [INFO] Final Memory: 18M/167M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:3.0.2:jar (make-a-jar) on project deploy: You have to use a classifier to attach supplemental artifacts to the project instead of replacing them. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException[/code]
原来如果在plugin中添加maven-jar-plugin插件之后,maven会运行两次maven-jar-plugin插件,第一次运行是打包当前工程的jar,第二次运行是执行在plugin中设置的jar,这样的话会生成两个jar包,这里就要用到classifier这个属性了。classifier是用来标识不同的jar包的名称的一个分类符,这个属性的值会添加到工程jar包的名称后面。例如当前工程的坐标:<groupId>deploy</groupId> <artifactId>deploy</artifactId> <version>0.0.1-SNAPSHOT</version>那就是意味着打包之后的jar包名称为deploy-0.0.1-SNAPSHOT.jar,而在plugin中设置要打的jar包是额外的jar包,classifier的值设置为bak:<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.0.2</version> <executions> <execution> <id>service-jar</id> <phase>package</phase> <goals> <goal>jar</goal> </goals> <configuration> <classifier>bak</classifier> <!-- 生成deploy-0.0.1-SNAPSHOT-bak.jar --> <classesDirectory>${project.build.directory}/webservice/</classesDirectory> </configuration> </execution> </executions> </plugin>
那最后在build目录下会有两个jar包,一个是deploy-0.0.1-SNAPSHOT.jar,另外一个则是deploy-0.0.1-SNAPSHOT-bak.jar这个deploy-0.0.1-SNAPSHOT-bak.jar是根据${project.build.directory}/webservice/这个目录下的文件来生成的jar包。总之,打出的jar包名称一定要区分,maven默认打多个jar包时不能覆盖掉原来的jar包,所以classifier就做了这个事情,可以从控制台打印的信息看到,maven执行了两次maven-jar-plugin的打包操作:[INFO] [INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ vbap3-webservice --- [WARNING] JAR will be empty - no content was marked for inclusion! [INFO] Building jar: /deploy/target/deploy-0.0.1-SNAPSHOT.jar [INFO] [INFO] --- maven-jar-plugin:3.0.2:jar (vbap-jar) @ vbap3-webservice --- [INFO] Building jar: /deploy/target/deploy-0.0.1-SNAPSHOT-bak.jar [INFO]
如果是只想要使用plugin生成的jar包,那么可以直接把execution的id改为default-jar,因为默认本身会调用一个maven-jar-plugin并且执行一个default-jar的操作,这里如果命名了一个default-jar的操作,那么就会按照这个操作进行打包,但是这个时候不能添加classifier分类符,因为这时只有一个jar包。<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.0.2</version> <executions> <execution> <id>default-jar</id> <phase>package</phase> <goals> <goal>jar</goal> </goals> <configuration> <!-- 没有classifier --> <classesDirectory>${project.build.directory}/webservice/</classesDirectory> </configuration> </execution> </executions> </plugin>
相关文章推荐
- MySql 执行语句错误 Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
- 【Angular2】You have to be inside an angular-cli project in order to use the generate command
- 【angular】you have to be inside an Angular CLI project in order to use the serve command
- CodeIgniter 错误: In order to use the Session class you are required to set an encryption key
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
- 错误信息:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server ve
- Project : error PRJ0050: Failed to register output. Please ensure you have the appropriate permissio
- 插入mysql语句报错:1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
- CodeIgniter 错误: In order to use the Session class you are required to set an encryption key
- 错误:The file “XXX” couldn’t be opened because you don’t have permission to view it.
- 网络访问时you might not have permission to use this network resource错误解决方法
- Android编译错误:You have tried to change the API from what has been previously approved.
- Android编译错误:You have tried to change the API from what has been previously approved.
- You have an error MySQL server version for the right syntax to use near 'TYPE=InnoDB' at line 20
- 错误:You need to use a Theme.AppCompat theme (or descendant) with this activity.
- You must have a copy of the scp binary locally to use the scp feature
- Android编译错误:You have tried to change the API from what has been previously approved.
- 关于 WMI Provider 不能连接的错误 - Cannot connect to WMI provider. You do not have permission or the server is unreachable.
- Internet Information Services is not installed. You must have Internet Information Services installed in order to use the SharePoint Products and Technologies Configuration Wizard
- CodeIgniter 错误: In order to use the Session class you are required to set an encryption key