简体   繁体   English

从自定义类导入时,无法对XMLBeans jar进行签名

[英]XMLBeans jar can't be signed when imported from custom class

In NetBeans I created an Exporter class that exports some data to an EXCEL file using APACHE POI, which uses XMLBeans. 在NetBeans中,我创建了一个Exporter类,它使用APACHE POI将一些数据导出到EXCEL文件,后者使用XMLBeans。

I added the APACHE POI 3.10.1 libraries by downloading the zip binaries and adding the jars manually. 我通过下载zip二进制文件并手动添加jar来添加APACHE POI 3.10.1库。

When I use this class inside the same project, everything runs correctly. 当我在同一个项目中使用这个类时,一切都正常运行。

Then I added this class to another project, via right click Libraries -> Add Project. 然后我通过右键单击Libraries - > Add Project将此类添加到另一个项目中。

But when I tried running this I got the following error while compiling. 但是当我尝试运行时,我在编译时遇到以下错误。

Signing JAR: C:\Users\c\p\dist\lib\xmlbeans-2.6.0.jar to C:\Users\c\p\dist\lib\xmlbeans-2.6.0.jar as nb-jfx
jarsigner: unable to sign jar: java.util.zip.ZipException: duplicate entry:    org/apache/xmlbeans/xml/stream/Location.class
Enter Passphrase for keystore: Enter key password for nb-jfx: 
C:\Users\c\p\nbproject\jfx-impl.xml:1465: The    following error occurred while executing this line:
C:\Users\c\p\nbproject\jfx-impl.xml:2968: The following error occurred while executing this line:
C:\Users\c\p\nbproject\jfx-impl.xml:1940: jarsigner   returned: 1

I don't know what this might be about, but is driving me crazy. 我不知道这可能是什么,但让我发疯。

There's a bug opened in XMLBEANS Jira that defines this issue. 在XMLBEANS Jira中打开了一个定义此问题的错误。 https://issues.apache.org/jira/browse/XMLBEANS-499 and one of the comments reports a fix. https://issues.apache.org/jira/browse/XMLBEANS-499其中一条评论报告修复。 I've not tried it yet but am in the process of doing so. 我还没试过,但我正在这样做。 Check it out. 看看这个。

Updated: Resolved. 更新:已解决。 In hindsight the resolution is obvious but painfully unnecessary if the .jar had been properly created. 事后看来,解决方案是显而易见的,但如果正确创建了.jar,那就很痛苦。 Unzip (I simply changed the .jar extension to .zip and proceeded) the .jar which will remove the duplicate .class files (8 in this case) then use the jar tool to recreate the .jar file. 解压缩(我只是将.jar扩展名更改为.zip并继续).jar将删除重复的.class文件(本例中为8),然后使用jar工具重新创建.jar文件。 The command is: "jar cf (path)\\xmlbeans-2.6.0.jar -C (unzipped folder path) ." 该命令是:“jar cf(path)\\ xmlbeans-2.6.0.jar -C(解压缩文件夹路径)。” Don't forget the period at the end of the command. 不要忘记命令末尾的句号。 Then I copied the new xmlbeans-2.6.0.jar into my lib directory and all is now well. 然后我将新的xmlbeans-2.6.0.jar复制到我的lib目录中,现在一切正常。 Hope this helps someone else! 希望这有助于其他人! :-) :-)

If you are using maven you can try to unpack the xmlbeans dependency. 如果您正在使用maven,则可以尝试解压缩xmlbeans依赖项。

<executions>
<execution>
    <id>unpack-dependencies</id>
    <phase>package</phase>
    <goals>
        <goal>unpack</goal>
    </goals>
    <configuration>
        <artifactItems>
            <artifactItem>
                <groupId>org.apache.xmlbeans</groupId>
                <artifactId>xmlbeans</artifactId>
                <version>2.6.0</version>
                <type>jar</type>
                <overWrite>true</overWrite>
                <outputDirectory>${project.build.directory}/classes</outputDirectory>
                <excludes>**/*test.class</excludes>
            </artifactItem>
        </artifactItems>
    </configuration>
</execution>
</executions>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM