Maven构建:解压缩jar的错误(mysql-connector-java)

时间:2017-02-09 03:40:37

标签: maven mysql-connector

我正在尝试使用以下命令构建我的dropwizard项目:

mvn package

我收到以下错误:

Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.3:shade (default) on project rest-api: Error creating shaded jar: error in opening zip file /Users/ldelaney/.m2/repository/mysql/mysql-connector-java/5.1.36/mysql-connector-java-5.1.36.jar

我已经检查过,罐子就在那里,就在maven看的地方。

我也试过把它吹走,跑步:

mvn clean
mvn package

但错误不会消失。我的IDE没有向我显示任何错误。

此外,这是我对POM的依赖:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.36</version>
</dependency>

这是整个POM文件。

<?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>com.company.test</groupId>
<artifactId>rest-api</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <dropwizard.version>1.0.5</dropwizard.version>
    <mongodriver.version>3.4.2</mongodriver.version>
    <mysqlConnector.version>5.1.36</mysqlConnector.version>
    <log4j.version>1.2.17</log4j.version>
</properties>

<dependencies>

    <!-- Drop Wizard -->
    <dependency>
        <groupId>io.dropwizard</groupId>
        <artifactId>dropwizard-core</artifactId>
        <version>${dropwizard.version}</version>
    </dependency>
    <dependency>
        <groupId>io.dropwizard</groupId>
        <artifactId>dropwizard-auth</artifactId>
        <version>${dropwizard.version}</version>
    </dependency>
    <dependency>
        <groupId>io.dropwizard</groupId>
        <artifactId>dropwizard-db</artifactId>
        <version>${dropwizard.version}</version>
    </dependency>
    <dependency>
        <groupId>io.dropwizard</groupId>
        <artifactId>dropwizard-hibernate</artifactId>
        <version>${dropwizard.version}</version>
    </dependency>

    <!-- MYSQL and Hibernate -->

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>${mysqlConnector.version}</version>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.4.193</version>
    </dependency>

    <!-- Log4j dependencies -->
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>${log4j.version}</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <createDependencyReducedPom>true</createDependencyReducedPom>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.DSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                        </excludes>
                    </filter>
                </filters>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>application.ServerApplication</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

有人有什么想法吗?

2 个答案:

答案 0 :(得分:1)

从OP响应看起来在.m2 / repository / mysql-connector-java / 5.1.36中只有pom.xml文件。请执行以下操作,

  1. 如果您在组织中使用nexus或ar​​tifactory存储库。删除mysql-connector坐标和相应的pom.xml文件。
  2. 确保配置防火墙,以便从here下载文件。默认情况下,中央存储库配置了maven安装。
  3. 如果您使用maven 2,请升级到maven 3.
  4. 我刚刚复制了你的pom,我能够成功构建。我也没有神秘或关系。你可以尝试一下,

    1. 转到maven安装并指定其他存储库位置。您应该转到/conf/settings.xml并取消注释并将#include <type_traits> template < int > struct II { }; template < const int& > struct RR { }; template < template <auto> typename Class, typename Type > struct Check : std::false_type { }; template < template <auto> typename Class, auto NonTypes > struct Check<Class,Class<NonTypes>> : std::true_type { }; constexpr int TEN = 10; constexpr const int& REF = TEN; static_assert(Check<II,II<TEN>>::value); // passes static_assert(Check<RR,RR<REF>>::value); // FAILS!? 更改为路径。确保你在那条路上做chmod +777。
    2. 如果问题仍然存在,请手动下载<localRepository>/path/to/local/repo</localRepository>并将其放在那里。看它是否有效。
    3. 如果2不起作用,则再次尝试步骤2,但使用-o标志运行mvn。这是脱机标志,maven不会下载依赖项。
    4. 如果它不起作用,你能用-X标志显示你的maven输出,

      mysql-connector-java-5.1.36.jar

答案 1 :(得分:0)

遇到了此问题:[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.1:shade (default) on project xxx: Error creating shaded jar: error in opening zip file /Users/username/.m2/repository/org/codehaus/groovy/groovy/2.2.0/groovy-2.2.0.jar -> [Help 1]

决议为rm -rf /Users/username/.m2/repository/org/codehaus/groovy/groovy/2.2.0,然后重新下载并重新开始工作。如果有帮助。