2 zhang5476499 zhang5476499 于 2016.03.29 11:47 提问

在控制台上maven打包报错。

楼主刚看徐晓斌的《maven实战》,正在控制台上鼓捣maven呢,mvn clean compile,mvn clean test也成功,然后mvn clean package打包也成功,但是由于打出来的Jar包没有指定main方法的位置,我就按照书上的案例,加入maven-shade-plugin插件,在pom.xml加入这话话,一直打包都是错误的。
pom.xml文件配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>xx.xx.xxx</groupId>
  <artifactId>hello-maven</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

 <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>1.2.1</version>
        <configuration>
          <transformers>
         <transformer implementation = "org.apache.maven.plugins.shade.resource.MainifestResourceTransformer">
         <mainClass>xx.xxx.xxx.hellomaven.App</mainClass>
         </transformer>
      </transformers>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build> 
</project>

控制台报错信息如下:

 [INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.731s
[INFO] Finished at: Tue Mar 29 11:40:17 CST 2016
[INFO] Final Memory: 10M/24M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:1.2.1
:shade (default) on project hello-maven: Unable to parse configuration of mojo o
rg.apache.maven.plugins:maven-shade-plugin:1.2.1:shade: ClassNotFoundException:
Class name which was explicitly given in configuration using 'implementation' at
tribute: 'org.apache.maven.plugins.shade.resource.MainifestResourceTransformer'
cannot be loaded -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[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 rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginConfigur
ationException

~\m2\repository\org\apache\maven\plugins\maven-compiler-plugin
里面居然是2.3.2版本,我的本地仓库下载下载下来的不是指定的那个1.2.1版本,这是怎么回事?

4个回答

u012538977
u012538977   2016.03.29 13:31
已采纳

http://bbs.csdn.net/topics/380145658?page=1 希望这个网页可以帮到你

zhang5476499
zhang5476499   2016.03.29 11:52

~\m2\repository\org\apache\maven\plugins\maven-compiler-plugin
里面居然是2.3.2版本,我的本地仓库下载下载下来的不是指定的那个1.2.1版本,这是怎么回事?

zhang5476499
zhang5476499   2016.03.29 13:36

已经解决问题了,我的解决方案是:重新去官网看这个补丁的地址,然后重新mvn clean package,其次,我写的类名错了,调用的类名有错,应该改为:
ManifestResourceTransformer

xymrl2046
xymrl2046   2016.03.29 13:36

org.apache.maven.plugins.shade.resource.MainifestResourceTransformer 类名打错了 ManifestResourceTransformer
提示类找不到

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!