java.util.zip.ZipException : duplicate entry: META_INF/LICENSE. txt

标签 java gradle java-web-start

这是我第一次使用 Java Web Start。这是我的应用程序的演示版本。我已将 JAR 上传到我的服务器,并创建了一个 JNLP 文件。当我在本地运行该文件时,出现如下所示的异常。

enter image description here

This是我正在阅读的引用文献,下面是我的 JNLP 文件。

DerbyPro.jnlp

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="" href="">
    <information>
        <title>Derby Pro</title>
        <vendor>Neon Orb</vendor>
        <icon href="http://neonorb.com/images/derby-pro/derby-pro-icon-hd.png"/>
        <offline-allowed/>
    </information>

    <resources>
        <j2se version="1.8+" href=
                "http://neonorb.com"/>
        <jar href="http://neonorb.com/clientportal/derby-pro-demo.jar"
             main="true" />
    </resources>

    <application-desc
            name="Derby Pro"
            main-class="com.neonorb.derbypro.main.DerbyPro"
            width="300"
            height="300">
    </application-desc>

    <update check="background"/>
</jnlp>

这是我的 build.gradle 文件,如下所示:./gradlew -Pversion=0.0.0 -Pdemo=true fatJar

group 'com.neonorb'

apply plugin: 'java'

sourceCompatibility = 1.8

project.description = 'Derby Pro is pinewood derby management software.'

//create a single Jar with all dependencies
task fatJar(type: Jar) {
    manifest {
        attributes 'Implementation-Version': version,
                'Main-Class': 'com.neonorb.derbypro.main.DerbyPro',
                'Demo': demo
    }
    baseName = project.name
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}

repositories {
    mavenCentral()
    maven {
        url "http://www.sparetimelabs.com/maven2"
    }
    mavenLocal()
}

dependencies {
    compile files('dfalex-0.9.2.jar')
    compile 'com.neonorb:commons:+'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.5.4'
    compile group: 'commons-cli', name: 'commons-cli', version: '1.3.1'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
    compile group: 'org.controlsfx', name: 'controlsfx', version: '8.40.10'
    compile group: 'org.fxmisc.easybind', name: 'easybind', version: '1.0.3'
    compile group: 'org.scream3r', name: 'jssc', version: '2.8.0'
    compile group: 'com.sparetimelabs', name: 'purejavacomm', version: '0.0.28'
    compile 'net.java.dev.jna:jna:4.2.1'
    compile 'commons-io:commons-io:2.4'
    testCompile group: 'junit', name: 'junit', version: '4.11'
    testCompile 'net.jodah:concurrentunit:0.4.2'
}

//Native launchers

//Windows

buildscript {
    repositories {
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }
    dependencies {
        classpath 'gradle.plugin.edu.sc.seis.gradle:launch4j:1.6.1'
    }
}

apply plugin: 'edu.sc.seis.launch4j'

launch4j {
    //outputDir = 'native/windows'
    bundledJrePath = 'jre'

    dontWrapJar = true
    jar = 'bin/derby-pro.jar'

    mainClassName = 'com.neonorb.derbypro.main.DerbyPro'
    icon = '../../src/main/resources/com/neonorb/derbypro/assets/derby-pro-icon-favicon.ico'
    outfile = 'DerbyPro.exe'

    companyName = 'Neon Orb'
    productName = 'Derby Pro'
}

//OS X

/*plugins {
    id "edu.sc.seis.macAppBundle" version "2.1.0"
}

macAppBundle {
    mainClassName = "com.example.myApp.Start"
    icon = "myIcon.icns"
    bundleJRE = true
    javaProperties.put("apple.laf.useScreenMenuBar", "true")
    backgroundImage = "doc/macbackground.png"
}*/

这是 list 目录。

enter image description here

这是 list 内容。

Manifest-Version: 1.0
Implementation-Version: 0.0.0
Main-Class: com.neonorb.derbypro.main.DerbyPro
Demo: true

最佳答案

您的 jar 文件包含重复的条目,这可能会在部署时导致问题。如果您对 jar 文件运行以下命令,您将看到重复的条目:

$ unzip -l derby-pro-demo.jar |grep META
        0  01-26-16 11:47   META-INF/
      116  01-26-16 11:47   META-INF/MANIFEST.MF
      321  06-09-15 18:42   META-INF/LICENSE
      825  06-09-15 18:42   META-INF/NOTICE
...
    11358  06-14-15 12:06   META-INF/LICENSE.txt
      172  06-14-15 12:06   META-INF/NOTICE.txt
...
    11358  04-03-15 14:30   META-INF/LICENSE.txt
      301  04-03-15 14:30   META-INF/NOTICE.txt

该问题是由 fatJar 引起的。请参阅 herehere

创建 fat jar 时,应该解决重复的条目。我没有使用 gradle 的经验。该问题(第一个链接)仍然标记为“开放”,所以我认为可能没有一个简单的解决方案。作为一种解决方法(如果这是可能的并且适合您),我可以想象首先将所有 jar 内容复制到临时目录。这将覆盖重复的条目。然后您可以从临时目录构建 fat jar。不过,我对此会非常小心。首先,一些重复的类文件可能是相关的,其次,许可证、通知等文件肯定会导致许可证问题。

关于java.util.zip.ZipException : duplicate entry: META_INF/LICENSE. txt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35020003/

相关文章:

java - 由于自签名或过时版本的安全异常,JDK 7u45 应用程序被阻止

java - BCC 收件人数量限制

java ShortBuffer数据传输没有整个缓冲区

java - 碰到窗口边缘时的字符碰撞

java - 在 CXF GET、PUT 和 DELETE 资源上获取 404,而 POST 工作正常

android - 在 'lintChecks' 配置中发现不止一个 jar

android - 将新的 Android 项目添加到 fork 的 repo

gradle - 从Gradle将jar和来源jar发布到Artifactory

java - Java Web Start Swing App 如何显示 servlet 信息?

java - 为什么 Java Web Start 说已签名的 jar 文件未签名?